public async Task When_Pass_Null_Parameters_To_GetNextAmr_Then_Exceptions_Are_Thrown()
        {
            // ARRANGE
            InitializeFakeObjects();

            // ACTS & ASSERTS
            await Assert.ThrowsAsync <ArgumentNullException>(() => _amrHelper.GetNextAmr(null, null)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ArgumentNullException>(() => _amrHelper.GetNextAmr("acr", null)).ConfigureAwait(false);
        }
예제 #2
0
        public async Task <ActionResult> ProcessRedirection(AuthorizationParameter authorizationParameter, string code, string subject, List <Claim> claims, string issuerName)
        {
            if (authorizationParameter == null)
            {
                throw new ArgumentNullException(nameof(authorizationParameter));
            }

            var client = await _clientRepository.GetClientByIdAsync(authorizationParameter.ClientId).ConfigureAwait(false);

            if (client == null)
            {
                throw new InvalidOperationException(string.Format(ErrorDescriptions.TheClientIdDoesntExist, authorizationParameter.ClientId));
            }

            ActionResult result;

            if (authorizationParameter.AcrValues != null && authorizationParameter.AcrValues.Any())
            {
                var nextAmr = await _amrHelper.GetNextAmr(authorizationParameter.AcrValues.First(), authorizationParameter.AmrValues).ConfigureAwait(false);

                if (!string.IsNullOrWhiteSpace(nextAmr))
                {
                    result = _actionResultFactory.CreateAnEmptyActionResultWithRedirection();
                    result.RedirectInstruction.Action = IdentityServerEndPoints.AuthenticateIndex;
                    result.AmrLst = authorizationParameter.AmrValues == null ? new List <string>() : authorizationParameter.AmrValues.ToList();
                    result.AmrLst.Add(nextAmr);
                    return(result);
                }
            }

            // Redirect to the consent page if the prompt parameter contains "consent"
            var prompts = _parameterParserHelper.ParsePrompts(authorizationParameter.Prompt);

            if (prompts != null && prompts.Contains(PromptParameter.consent))
            {
                result        = _actionResultFactory.CreateAnEmptyActionResultWithRedirection();
                result.AmrLst = authorizationParameter.AmrValues == null ? new List <string>() : authorizationParameter.AmrValues.ToList();
                result.RedirectInstruction.Action = IdentityServerEndPoints.ConsentIndex;
                result.RedirectInstruction.AddParameter("code", code);
                return(result);
            }

            var assignedConsent = await _consentHelper.GetConfirmedConsentsAsync(subject, authorizationParameter).ConfigureAwait(false);

            // If there's already one consent then redirect to the callback
            if (assignedConsent != null)
            {
                result        = _actionResultFactory.CreateAnEmptyActionResultWithRedirectionToCallBackUrl();
                result.AmrLst = authorizationParameter.AmrValues == null ? new List <string>() : authorizationParameter.AmrValues.ToList();
                var claimsIdentity  = new ClaimsIdentity(claims, "simpleIdentityServer");
                var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
                await _generateAuthorizationResponse.ExecuteAsync(result, authorizationParameter, client, issuerName, claimsPrincipal.GetSubject()).ConfigureAwait(false);

                var responseMode = authorizationParameter.ResponseMode;
                if (responseMode == ResponseMode.None)
                {
                    var responseTypes     = _parameterParserHelper.ParseResponseTypes(authorizationParameter.ResponseType);
                    var authorizationFlow = GetAuthorizationFlow(responseTypes, authorizationParameter.State);
                    responseMode = GetResponseMode(authorizationFlow);
                }

                result.RedirectInstruction.ResponseMode = responseMode;
                return(result);
            }

            // If there's no consent & there's no consent prompt then redirect to the consent screen.
            result        = _actionResultFactory.CreateAnEmptyActionResultWithRedirection();
            result.AmrLst = authorizationParameter.AmrValues == null ? new List <string>() : authorizationParameter.AmrValues.ToList();
            result.RedirectInstruction.Action = IdentityServerEndPoints.ConsentIndex;
            result.RedirectInstruction.AddParameter("code", code);
            return(result);
        }