コード例 #1
0
        internal static async Task <MobileConnectStatus> RequestUserInfo(IIdentityService _identity, DiscoveryResponse discoveryResponse, string accessToken, MobileConnectConfig _config, MobileConnectRequestOptions options)
        {
            string userInfoUrl = discoveryResponse?.OperatorUrls?.UserInfoUrl;

            if (string.IsNullOrEmpty(userInfoUrl))
            {
                Log.Error(() => $"UserInfo was not supported for issuer={discoveryResponse?.ProviderMetadata?.Issuer}");
                return(MobileConnectStatus.Error(ErrorCodes.NotSupported, "UserInfo not supported with current operator", null));
            }

            try
            {
                var response = await _identity.RequestUserInfo(userInfoUrl, accessToken);

                return(MobileConnectStatus.UserInfo(response));
            }
            catch (MobileConnectInvalidArgumentException e)
            {
                Log.Error(() => $"An invalid argument was passed to RequestUserInfo arg={e.Argument}");
                return(MobileConnectStatus.Error(ErrorCodes.InvalidArgument, string.Format("An argument was found to be invalid during the process. The argument was {0}.", e.Argument), e));
            }
            catch (MobileConnectEndpointHttpException e)
            {
                Log.Error(() => $"A general http error occurred in RequestUserInfo userInfoUrl={userInfoUrl}");
                return(MobileConnectStatus.Error(ErrorCodes.HttpFailure, "An HTTP failure occured while calling the operator token endpoint, the endpoint may be inaccessible", e));
            }
            catch (Exception e)
            {
                Log.Error(() => $"A general error occurred in RequestUserInfo userInfoUrl={userInfoUrl}");
                return(MobileConnectStatus.Error(ErrorCodes.Unknown, "A failure occured while requesting a token", e));
            }
        }