private string StartAuth(
            DiscoveryResponse discoveryResponse,
            string subscriberId,
            HttpRequestMessage request,
            string msisdn,
            string mcc,
            string mnc,
            string sourceIp)
        {
            string scope = OperatorParams.scope;

            var options = new MobileConnectRequestOptions
            {
                Scope          = scope,
                Context        = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                BindingMessage = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                ClientName     = OperatorParams.clientName,
                AcrValues      = OperatorParams.acrValues
            };

            var status =
                MobileConnect.StartAuthentication(request, discoveryResponse, subscriberId, null, null, options, ApiVersion);

            if (HandleErrorMsg(status))
            {
                return(null);
            }

            SetSessionCache(status, msisdn, mcc, mnc, sourceIp);
            return(status.Url);
        }
        public async Task <IHttpActionResult> MCC_MNC_DiscoveryCallback(string mcc_mnc, string subscriber_id = "")
        {
            var requestOptions = new MobileConnectRequestOptions
            {
                Context        = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                BindingMessage = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                ClientName     = OperatorParams.clientName,
                AcrValues      = OperatorParams.acrValues
            };

            var mcc_mncArray = mcc_mnc.Split(new char[] { '_' });
            var mcc          = mcc_mncArray[0];
            var mnc          = mcc_mncArray[1];

            var status = await MobileConnect.AttemptDiscoveryAsync(
                RequestMessage, null, mcc, mnc, true, IncludeRequestIp, requestOptions);

            if (status.DiscoveryResponse != null)
            {
                SetDiscoveryCache(null, mcc, mnc, null, status.DiscoveryResponse);

                var url = CallStartAuth(status.DiscoveryResponse, subscriber_id, RequestMessage, null, mcc, mnc,
                                        null);
                return(GetHttpMsgWithRedirect(url));
            }
            else
            {
                return(GetHttpMsgWithRedirect(status.Url, status.ErrorMessage));
            }
        }
示例#3
0
        public async Task AttemptDiscoveryShouldResolveToOperatorSelectionWithNoArguments()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var response       = await _mobileConnect.AttemptDiscoveryAsync(null, null, null, requestOptions);

            Assert.AreEqual(MobileConnectResponseType.OperatorSelection, response.ResponseType);
            Assert.IsNotEmpty(response.Url);
        }
示例#4
0
        public async Task AttemptDiscoveryShouldSucceedWithTestMCCMNC()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var response       = await _mobileConnect.AttemptDiscoveryAsync(null, _testConfig.ValidMCC, _testConfig.ValidMNC, requestOptions);

            Assert.AreEqual(MobileConnectResponseType.StartAuthentication, response.ResponseType);
            Assert.IsNotNull(response.DiscoveryResponse);
        }
示例#5
0
        public async Task AttemptDiscoveryShouldFailWithInvalidFormatMCCMNC()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var response       = await _mobileConnect.AttemptDiscoveryAsync(null, "99999", "99", requestOptions);

            Assert.AreEqual(MobileConnectResponseType.Error, response.ResponseType);
            Assert.IsNotNull(response.DiscoveryResponse);
        }
示例#6
0
        public async Task AttemptDiscoveryShouldFailWithNonExistentMCCMNC()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var response       = await _mobileConnect.AttemptDiscoveryAsync(null, _testConfig.InvalidMCC, _testConfig.InvalidMNC, requestOptions);

            Assert.AreEqual(MobileConnectResponseType.Error, response.ResponseType);
            Assert.IsNotNull(response.DiscoveryResponse);
        }
        public async Task AttemptDiscoveryShouldFailWithInvalidFormatMCCMNC()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var request        = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            var response       = await _mobileConnect.AttemptDiscoveryAsync(request, null, "99999", "99", true, false, requestOptions);

            Assert.AreEqual(MobileConnectResponseType.Error, response.ResponseType);
            Assert.IsNotNull(response.DiscoveryResponse);
        }
        public async Task AttemptDiscoveryShouldSucceedWithTestMSISDN()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var request        = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            var response       = await _mobileConnect.AttemptDiscoveryAsync(request, _testConfig.ValidMSISDN, null, null, true, false, requestOptions);

            Assert.AreEqual(MobileConnectResponseType.StartAuthentication, response.ResponseType);
            Assert.IsNotNull(response.DiscoveryResponse);
        }
        public async Task AttemptDiscoveryShouldResolveToOperatorSelectionWithNoArguments()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var request        = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            var response       = await _mobileConnect.AttemptDiscoveryAsync(request, null, null, null, true, false, requestOptions);

            Assert.AreEqual(MobileConnectResponseType.OperatorSelection, response.ResponseType);
            Assert.IsNotEmpty(response.Url);
        }
        public async Task AttemptDiscoveryShouldFailWithNonExistentMSISDN()
        {
            var requestOptions = new MobileConnectRequestOptions();
            var request        = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            var response       = await _mobileConnect.AttemptDiscoveryAsync(request, _testConfig.InvalidMSISDN, null, null, true, false, requestOptions);

            Assert.AreEqual(MobileConnectResponseType.Error, response.ResponseType);
            Assert.IsNotNull(response.DiscoveryResponse);
        }
示例#11
0
        public async Task <IHttpActionResult> StartDiscovery(string msisdn = "", string sourceIp = "")
        {
            var requestOptions = new MobileConnectRequestOptions {
                ClientIP = sourceIp
            };
            var status = await _mobileConnect.AttemptDiscoveryAsync(Request, msisdn, null, null, true, requestOptions);

            return(CreateResponse(status));
        }
示例#12
0
        public async Task <IHttpActionResult> HandleRedirect(string sdksession = null, string mcc_mnc = null, string code = null, string expectedState = null, string expectedNonce = null)
        {
            // Accept valid results and results indicating validation was skipped due to missing support on the provider
            var requestOptions = new MobileConnectRequestOptions {
                AcceptedValidationResults = Authentication.TokenValidationResult.Valid | Authentication.TokenValidationResult.IdTokenValidationSkipped
            };
            var response = await _mobileConnect.HandleUrlRedirectAsync(Request, Request.RequestUri, sdksession, expectedState, expectedNonce, requestOptions);

            return(CreateResponse(response));
        }
示例#13
0
        //[TestCase("r2-ref")]
        public async Task MobileConnectWebInterfaceShouldWorkEndToEndWithCache(string configKey)
        {
            RestClient      restClient     = new RestClient();
            IDiscoveryCache cache          = new ConcurrentDiscoveryCache();
            IDiscovery      discovery      = new GSMA.MobileConnect.Discovery.Discovery(cache, restClient);
            IAuthentication authentication = new GSMA.MobileConnect.Authentication.Authentication(restClient);

            var testConfig             = TestConfig.GetConfig(configKey);
            MobileConnectConfig config = new MobileConnectConfig()
            {
                DiscoveryUrl = testConfig.DiscoveryUrl,
                ClientId     = testConfig.ClientId,
                ClientSecret = testConfig.ClientSecret,
                RedirectUrl  = testConfig.RedirectUrl
            };

            MobileConnectRequestOptions blankOptions  = new MobileConnectRequestOptions();
            MobileConnectWebInterface   mobileConnect = new MobileConnectWebInterface(discovery, authentication, config);

            //Attempt discovery
            var request = new HttpRequestMessage();
            var status  = await mobileConnect.AttemptDiscoveryAsync(request, testConfig.ValidMSISDN, null, null, true, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.StartAuthorization, status.ResponseType);

            var session         = status.SDKSession;
            var encryptedMsisdn = status.DiscoveryResponse.ResponseData.subscriber_id;
            var state           = "zmxncbvalskdjfhgqpwoeiruty";
            var nonce           = "qpwoeirutyalskdjfhgzmxncbv";

            //Start Authorization
            request = new HttpRequestMessage();
            status  = await mobileConnect.StartAuthorization(request, session, encryptedMsisdn, state, nonce, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.Authorization, status.ResponseType);

            //Inconclusive at this point because the sandbox no longer allows us to follow redirects easily
            Assert.Inconclusive("Can't follow redirects in sandbox");

            //Authorization
            request = new HttpRequestMessage();
            var redirectedUrl = await FollowRedirects(status.Url, _basicRequestHeaders, testConfig.RedirectUrl);

            Assert.That(() => redirectedUrl.AbsoluteUri.StartsWith(testConfig.RedirectUrl));
            Assert.AreEqual(state, HttpUtils.ExtractQueryValue(redirectedUrl.Query, "state"));

            //Handle auth redirect and request token
            request = new HttpRequestMessage();
            status  = await mobileConnect.HandleUrlRedirectAsync(request, redirectedUrl, session, state, nonce);

            Assert.AreEqual(MobileConnectResponseType.Complete, status.ResponseType);
            Assert.IsNotEmpty(status.TokenResponse.ResponseData.AccessToken);
        }
示例#14
0
        public async Task <IHttpActionResult> StartAuthentication(string sdksession = null, string subscriberId = null, string scope = null)
        {
            var options = new MobileConnectRequestOptions
            {
                Scope          = scope,
                Context        = "demo",
                BindingMessage = "demo auth",
            };

            var response = await _mobileConnect.StartAuthentication(Request, sdksession, subscriberId, null, null, options);

            return(CreateResponse(response));
        }
示例#15
0
        public async Task RequestTokenAcceptInvalidTokenIfFlaggedAsAcceptedResult()
        {
            var options = new MobileConnectRequestOptions {
                AcceptedValidationResults = TokenValidationResult.Valid | TokenValidationResult.InvalidNonce
            };

            _restClient.QueueParallelResponses(Tuple.Create <string, object>(_discoveryResponse.OperatorUrls.JWKSUrl, _responses["jwks"]),
                                               Tuple.Create <string, object>(_discoveryResponse.OperatorUrls.RequestTokenUrl, _responses["token"]));

            var result = await _mobileConnect.RequestTokenAsync(_discoveryResponse, new Uri($"{_config.RedirectUrl}?code=123123123456&state=zxcvbnm"), "zxcvbnm", "12345678", options);

            Assert.AreEqual(MobileConnectResponseType.Complete, result.ResponseType);
            Assert.AreEqual(TokenValidationResult.InvalidNonce, result.TokenResponse.ValidationResult);
        }
示例#16
0
        public async Task <IHttpActionResult> RequestHeadlessAuthentication(string sdksession = null, string subscriberId = null, string scope = null)
        {
            var options = new MobileConnectRequestOptions
            {
                Scope          = scope,
                Context        = "headless",
                BindingMessage = "demo headless",
                AutoRetrieveIdentityHeadless = true,
            };

            var response = await _mobileConnect.RequestHeadlessAuthenticationAsync(Request, sdksession, subscriberId, null, null, options);

            return(CreateResponse(response));
        }
示例#17
0
        public async Task MobileConnectWebInterfaceShouldWorkEndToEndHeadlessWithRevoke(string configKey)
        {
            RestClient             restClient     = new RestClient();
            ICache                 cache          = null;
            IDiscoveryService      discovery      = new GSMA.MobileConnect.Discovery.DiscoveryService(cache, restClient);
            IAuthenticationService authentication = new GSMA.MobileConnect.Authentication.AuthenticationService(restClient);
            IIdentityService       identity       = new GSMA.MobileConnect.Identity.IdentityService(restClient);
            IJWKeysetService       jwks           = new GSMA.MobileConnect.Authentication.JWKeysetService(restClient, cache);

            var testConfig             = TestConfig.GetConfig(configKey);
            MobileConnectConfig config = new MobileConnectConfig()
            {
                DiscoveryUrl = testConfig.DiscoveryUrl,
                ClientId     = testConfig.ClientId,
                ClientSecret = testConfig.ClientSecret,
                RedirectUrl  = testConfig.RedirectUrl
            };

            MobileConnectRequestOptions blankOptions  = new MobileConnectRequestOptions();
            MobileConnectWebInterface   mobileConnect = new MobileConnectWebInterface(discovery, authentication, identity, jwks, config);

            //Attempt discovery
            var request = new HttpRequestMessage();
            var status  = await mobileConnect.AttemptDiscoveryAsync(request, testConfig.ValidMSISDN, null, null, true, false, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.StartAuthentication, status.ResponseType, $"{status.ErrorCode} - {status.ErrorMessage}");

            var discoveryResponse = status.DiscoveryResponse;
            var encryptedMsisdn   = status.DiscoveryResponse.ResponseData.subscriber_id;
            var state             = "zmxncbvalskdjfhgqpwoeiruty";
            var nonce             = "qpwoeirutyalskdjfhgzmxncbv";

            //Start Authorization
            var authOptions = new MobileConnectRequestOptions {
                Scope = "mc_authz", BindingMessage = "auth test", Context = "test"
            };

            request = new HttpRequestMessage();
            status  = await mobileConnect.RequestHeadlessAuthenticationAsync(request, discoveryResponse, encryptedMsisdn, state, nonce, authOptions);

            Assert.AreEqual(MobileConnectResponseType.Complete, status.ResponseType, $"{status.ErrorCode} - {status.ErrorMessage}");
            Assert.IsNotEmpty(status.TokenResponse.ResponseData.AccessToken);
            Assert.IsNotEmpty(status.TokenResponse.ResponseData.IdToken);

            //Revoke Token
            status = await mobileConnect.RevokeTokenAsync(request, status.TokenResponse.ResponseData.AccessToken, null, discoveryResponse);

            Assert.AreEqual(MobileConnectResponseType.TokenRevoked, status.ResponseType, $"{status.ErrorCode} - {status.ErrorMessage}");
        }
示例#18
0
        public async Task <IHttpActionResult> StartManualDiscoveryWithMetadata(string subId = "", string clientId = "", string clientName = "", string clientSecret = "")
        {
            var mobileConnectRequestOptions = new MobileConnectRequestOptions()
            {
                Scope          = "",
                Context        = "demo",
                BindingMessage = "demo auth",
            };

            MobileConnectWebInterface mobileConnectWebInterface = new MobileConnectWebInterface(mobileConnectConfig, new ConcurrentCache());
            var discoveryResponse = await mobileConnectWebInterface.GenerateDiscoveryManually(clientId, clientSecret, subId, clientName, operatorURLs);

            var status = mobileConnectWebInterface.StartAuthentication(Request, discoveryResponse, subId, null, null, mobileConnectRequestOptions);

            return(CreateResponse(status));
        }
        public void ShouldFillDiscoveryOptions()
        {
            var isUsingMobileData = true;
            var localClientIp     = "111.11.11.11";
            var clientIp          = "222.22.22.22";

            var actual = new MobileConnectRequestOptions
            {
                IsUsingMobileData = isUsingMobileData,
                LocalClientIP     = localClientIp,
                ClientIP          = clientIp,
            };

            Assert.AreEqual(isUsingMobileData, actual.IsUsingMobileData);
            Assert.AreEqual(localClientIp, actual.LocalClientIP);
            Assert.AreEqual(clientIp, actual.ClientIP);
        }
        public void ShouldFillAuthenticationOptions()
        {
            var display       = "display type";
            var prompt        = "prompt";
            var uiLocales     = "ui locales";
            var claimsLocales = "claims locales";
            var idTokenHint   = "id token";
            var loginHint     = "login hint";
            var dtbs          = "data to be sent";
            var scope         = "scope value";
            var acr           = "acr value";
            var maxAge        = 1200;
            var claimsJson    = "claims json";
            var claims        = new MobileConnect.Claims.ClaimsParameter();

            var actual = new MobileConnectRequestOptions
            {
                Display       = display,
                Prompt        = prompt,
                UiLocales     = uiLocales,
                ClaimsLocales = claimsLocales,
                IdTokenHint   = idTokenHint,
                LoginHint     = loginHint,
                Dtbs          = dtbs,
                Scope         = scope,
                AcrValues     = acr,
                MaxAge        = maxAge,
                ClaimsJson    = claimsJson,
                Claims        = claims,
            };

            Assert.AreEqual(display, actual.Display);
            Assert.AreEqual(prompt, actual.Prompt);
            Assert.AreEqual(uiLocales, actual.UiLocales);
            Assert.AreEqual(claimsLocales, actual.ClaimsLocales);
            Assert.AreEqual(idTokenHint, actual.IdTokenHint);
            Assert.AreEqual(loginHint, actual.LoginHint);
            Assert.AreEqual(dtbs, actual.Dtbs);
            Assert.AreEqual(scope, actual.Scope);
            Assert.AreEqual(acr, actual.AcrValues);
            Assert.AreEqual(maxAge, actual.MaxAge);
            Assert.AreEqual(claimsJson, actual.ClaimsJson);
            Assert.AreEqual(claims, actual.Claims);
        }
        private async Task StartAuthentication(MobileConnectStatus response)
        {
            _state             = Utils.Security.GenerateSecureNonce();
            _nonce             = Utils.Security.GenerateSecureNonce();
            _discoveryResponse = response.DiscoveryResponse;
            _authOptions       = new MobileConnectRequestOptions
            {
                Scope          = GetScope(),
                Context        = "demo",
                BindingMessage = "demo auth",
                // Accept valid results and results indicating validation was skipped due to missing support on the provider
                AcceptedValidationResults = TokenValidationResult.Valid | TokenValidationResult.IdTokenValidationSkipped,
            };

            var newResponse = _mobileConnect.StartAuthentication(_discoveryResponse,
                                                                 response.DiscoveryResponse.ResponseData.subscriber_id, _state, _nonce, _authOptions);

            await HandleResponse(newResponse);
        }
示例#22
0
        public void ShouldFillAuthenticationOptions()
        {
            var display       = "display type";
            var prompt        = "prompt";
            var uiLocales     = "ui locales";
            var claimsLocales = "claims locales";
            var idTokenHint   = "id token";
            var loginHint     = "login hint";
            var dtbs          = "data to be sent";
            var expected      = new MobileConnect.Authentication.AuthenticationOptions
            {
                Display       = display,
                Prompt        = prompt,
                UiLocales     = uiLocales,
                ClaimsLocales = claimsLocales,
                IdTokenHint   = idTokenHint,
                LoginHint     = loginHint,
                Dtbs          = dtbs,
            };

            var actual = new MobileConnectRequestOptions
            {
                Display       = display,
                Prompt        = prompt,
                UiLocales     = uiLocales,
                ClaimsLocales = claimsLocales,
                IdTokenHint   = idTokenHint,
                LoginHint     = loginHint,
                Dtbs          = dtbs,
            };

            Assert.AreEqual(display, actual.Display);
            Assert.AreEqual(prompt, actual.Prompt);
            Assert.AreEqual(uiLocales, actual.UiLocales);
            Assert.AreEqual(claimsLocales, actual.ClaimsLocales);
            Assert.AreEqual(idTokenHint, actual.IdTokenHint);
            Assert.AreEqual(loginHint, actual.LoginHint);
            Assert.AreEqual(dtbs, actual.Dtbs);
        }
示例#23
0
        public async Task <IHttpActionResult> StartAuthentication(string sdksession = null, string subscriberId = null, string scope = null)
        {
            if (scope == null && _operatorUrLs.ProviderMetadataUrl == null)
            {
                _apiVersion = Config.Constants.Version1;
            }
            else if (scope == null)
            {
                _apiVersion = Config.Constants.Version2;
            }

            var options = new MobileConnectRequestOptions
            {
                Scope          = scope,
                Context        = _apiVersion.Equals(Config.Constants.Version2) ? Config.Constants.ContextBindingMsg : null,
                BindingMessage = _apiVersion.Equals(Config.Constants.Version2) ? Config.Constants.ContextBindingMsg : null
            };

            var response = await _mobileConnect.StartAuthentication(Request, sdksession, subscriberId, null, null, options);

            return(CreateResponse(response));
        }
        private async Task <MobileConnectStatus> AttemptDiscovery(string msisdn, string mcc, string mnc, string sourceIp,
                                                                  HttpRequestMessage request)
        {
            var requestOptions = new MobileConnectRequestOptions {
                ClientIP = sourceIp
            };
            var discoveryOptions = requestOptions?.DiscoveryOptions ?? new DiscoveryOptions();

            discoveryOptions.MSISDN        = msisdn;
            discoveryOptions.IdentifiedMCC = mcc;
            discoveryOptions.IdentifiedMNC = mnc;

            var status = await MobileConnect.AttemptDiscoveryAsync(request, msisdn, mcc, mnc, true, IncludeRequestIp,
                                                                   requestOptions);

            if (HandleErrorMsg(status))
            {
                status = await MobileConnect.AttemptDiscoveryAsync(
                    request, null, null, null, false, false, requestOptions);
            }

            return(status);
        }
示例#25
0
        public async Task <IHttpActionResult> StartManualDiscoveryWithoutMetadata(string subId = "", string clientId = "", /*string clientName = "", */ string clientSecret = "")
        {
            var mobileConnectRequestOptions = new MobileConnectRequestOptions()
            {
                Scope          = "",
                Context        = "demo",
                BindingMessage = "demo auth",
            };

            var operatorUrlsWd = new OperatorUrls
            {
                AuthorizationUrl = operatorURLs.AuthorizationUrl,
                RequestTokenUrl  = operatorURLs.RequestTokenUrl,
                UserInfoUrl      = operatorURLs.UserInfoUrl
            };

            MobileConnectWebInterface mobileConnectWebInterface = new MobileConnectWebInterface(mobileConnectConfig, new ConcurrentCache());
            var discoveryResponse = await mobileConnectWebInterface.GenerateDiscoveryManually(clientId, clientSecret, subId, "appName" /*clientName*/, operatorUrlsWd);

            var status = mobileConnectWebInterface.StartAuthentication(Request, discoveryResponse, subId, null, null, mobileConnectRequestOptions);

            return(CreateResponse(status));
        }
示例#26
0
        private string StartAuth(
            DiscoveryResponse discoveryResponse,
            string msisdn,
            HttpRequestMessage request)
        {
            string scope = OperatorParams.scope;

            string loginHint = null;

            if (!string.IsNullOrEmpty(msisdn))
            {
                loginHint = $"{Parameters.MSISDN}:{msisdn}";
            }

            var options = new MobileConnectRequestOptions
            {
                Scope          = scope,
                Context        = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                BindingMessage = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                ClientName     = OperatorParams.clientName,
                AcrValues      = OperatorParams.acrValues,
                LoginHint      = loginHint
            };

            var status =
                MobileConnect.StartAuthentication(request, discoveryResponse, null, null, null, options, ApiVersion);

            if (HandleErrorMsg(status))
            {
                return(null);
            }

            SetSessionCache(status, discoveryResponse, status.Nonce);

            return(status.Url);
        }
        /// <summary>
        /// Executes a HTTP GET to the supplied uri with optional basic auth, cookies and query params
        /// </summary>
        /// <param name="uri">Base uri of GET request</param>
        /// <param name="authentication">Authentication value to be used (if auth required)</param>
        /// <param name="xRedirect">x-Redirect header(if identified)</param>
        /// <param name="sourceIp">Source request IP (if identified)</param>
        /// <param name="queryParams">Query params to be added to the base url (if required)</param>
        /// <param name="cookies">Cookies to be added to the request (if required)</param>
        /// <returns>RestResponse containing status code, headers and content</returns>
        public virtual async Task <String> GetAsyncWithRedirect(string uri, RestAuthentication authentication, MobileConnectRequestOptions requestOptions, string xRedirect = "APP", string sourceIp = null, IEnumerable <BasicKeyValuePair> queryParams = null, IEnumerable <BasicKeyValuePair> cookies = null)
        {
            UriBuilder builder = new UriBuilder(uri);

            builder.AddQueryParams(queryParams);

            var request  = CreateRequest(HttpMethod.Get, builder.Uri, xRedirect, authentication, sourceIp, cookies);
            var response = await _client.SendAsync(request);

            return(response.RequestMessage.RequestUri.ToString());
        }
        public async Task <IHttpActionResult> DiscoveryCallback(
            string state             = null,
            string error             = null,
            string error_description = null,
            string description       = null)
        {
            if (!string.IsNullOrEmpty(error))
            {
                return(CreateResponse(MobileConnectStatus.Error(error, error_description != null ? error_description : description, new Exception())));
            }

            var options = new MobileConnectRequestOptions
            {
                AcceptedValidationResults = Authentication.TokenValidationResult.Valid |
                                            Authentication.TokenValidationResult.IdTokenValidationSkipped,
                Context        = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                BindingMessage = ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3) ? Utils.Constants.ContextBindingMsg : null,
                ClientName     = OperatorParams.clientName,
                AcrValues      = OperatorParams.acrValues
            };

            Uri requestUri = Request.RequestUri;

            SessionData sessionData = SessionCache.Get(state);

            MobileConnectStatus status = await MobileConnect.HandleUrlRedirectAsync(Request, requestUri, sessionData.DiscoveryResponse,
                                                                                    state, sessionData.Nonce, options, ApiVersion);


            var idTokenResponseModel =
                JsonConvert.DeserializeObject <IdTokenResponse>(status.TokenResponse.DecodedIdTokenPayload);


            MobileConnectStatus response = null;

            if (idTokenResponseModel.nonce.Equals(sessionData.Nonce))
            {
                if (ApiVersion.Equals(Utils.Constants.VERSION1_1) &
                    !string.IsNullOrEmpty(sessionData.DiscoveryResponse.OperatorUrls.UserInfoUrl))
                {
                    for (int scopeIndex = 0; scopeIndex < UserInfoScopes.Length; scopeIndex++)
                    {
                        if (OperatorParams.scope.Contains(UserInfoScopes[scopeIndex]))
                        {
                            response = await RequestUserInfo(sessionData.DiscoveryResponse,
                                                             status.TokenResponse.ResponseData.AccessToken);

                            return(CreateIdentityResponse(status, response));
                        }
                    }
                }

                if ((ApiVersion.Equals(Utils.Constants.VERSION2_0) || ApiVersion.Equals(Utils.Constants.VERSION2_3)) &
                    !string.IsNullOrEmpty(sessionData.DiscoveryResponse.OperatorUrls.PremiumInfoUrl))
                {
                    for (int scopeIndex = 0; scopeIndex < IdentityScopes.Length; scopeIndex++)
                    {
                        if (OperatorParams.scope.Contains(IdentityScopes[scopeIndex]))
                        {
                            response = await RequestPremiumInfo(sessionData.DiscoveryResponse,
                                                                status.TokenResponse.ResponseData.AccessToken);

                            return(CreateIdentityResponse(status, response));
                        }
                    }
                }
            }
            else
            {
                response = MobileConnectStatus.Error(
                    ErrorCodes.InvalidArgument, "nonce is incorrect", new Exception());
                return(CreateResponse(response));
            }

            // return CreateResponse(status);
            return(CreateIdentityResponse(status));
        }