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));
            }
        }
        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 void equals_override_should_return_false_when_api_versions_are_not_equal()
        {
            // arrange
            var    apiVersion = new ApiVersion(Today);
            object obj        = new ApiVersion(1, 0);

            // act
            var equal = apiVersion.Equals(obj);

            // assert
            equal.Should().BeFalse();
        }
Ejemplo n.º 4
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);
        }
        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));
        }