Пример #1
0
        public async Task <IActionResult> Consent([FromForm] InputModel input)
        {
            var request = await _interaction.GetLoginRequestByInternalIdAsync(input.Id);

            var viewModel = BuildViewModelAsync(request, input.Id, input);

            CompleteBackchannelLoginRequest result = null;

            // user clicked 'no' - send back the standard 'access_denied' response
            if (input.Button == "no")
            {
                result = new CompleteBackchannelLoginRequest(input.Id);

                // emit event
                await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues))
                .ConfigureAwait(false);
            }
            // user clicked 'yes' - validate the data
            else if (input.Button == "yes")
            {
                // if the user consented to some scope, build the response model
                if (input.ScopesConsented != null && input.ScopesConsented.Any())
                {
                    var scopes = input.ScopesConsented;
                    if (ConsentOptions.EnableOfflineAccess == false)
                    {
                        scopes = scopes.Where(x => x != StandardScopes.OfflineAccess);
                    }

                    result = new CompleteBackchannelLoginRequest(input.Id)
                    {
                        ScopesValuesConsented = scopes.ToArray(),
                        Description           = input.Description
                    };

                    // emit event
                    await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, result.ScopesValuesConsented, false))
                    .ConfigureAwait(false);;
                }
                else
                {
                    ModelState.AddModelError(string.Empty, ConsentOptions.MustChooseOneErrorMessage);
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, ConsentOptions.InvalidSelectionErrorMessage);
            }

            if (result != null)
            {
                // communicate outcome of consent back to identityserver
                await _interaction.CompleteLoginRequestAsync(result);

                return(RedirectToPage("/Account/Manage/Ciba", new { area = "Identity" }));
            }

            return(View(viewModel));
        }
Пример #2
0
    public async Task <IActionResult> OnPost()
    {
        // validate return url is still valid
        var request = await _interaction.GetLoginRequestByInternalIdAsync(Input.Id);

        if (request == null || request.Subject.GetSubjectId() != User.GetSubjectId())
        {
            _logger.LogError("Invalid id {id}", Input.Id);
            return(RedirectToPage("/Home/Error/Index"));
        }

        CompleteBackchannelLoginRequest result = null;

        // user clicked 'no' - send back the standard 'access_denied' response
        if (Input?.Button == "no")
        {
            result = new CompleteBackchannelLoginRequest(Input.Id);

            // emit event
            await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues));
        }
        // user clicked 'yes' - validate the data
        else if (Input?.Button == "yes")
        {
            // if the user consented to some scope, build the response model
            if (Input.ScopesConsented != null && Input.ScopesConsented.Any())
            {
                var scopes = Input.ScopesConsented;
                if (ConsentOptions.EnableOfflineAccess == false)
                {
                    scopes = scopes.Where(x => x != Duende.IdentityServer.IdentityServerConstants.StandardScopes.OfflineAccess);
                }

                result = new CompleteBackchannelLoginRequest(Input.Id)
                {
                    ScopesValuesConsented = scopes.ToArray(),
                    Description           = Input.Description
                };

                // emit event
                await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, result.ScopesValuesConsented, false));
            }
            else
            {
                ModelState.AddModelError("", ConsentOptions.MustChooseOneErrorMessage);
            }
        }
        else
        {
            ModelState.AddModelError("", ConsentOptions.InvalidSelectionErrorMessage);
        }

        if (result != null)
        {
            // communicate outcome of consent back to identityserver
            await _interaction.CompleteLoginRequestAsync(result);

            return(RedirectToPage("/Ciba/All"));
        }

        // we need to redisplay the consent UI
        View = await BuildViewModelAsync(Input.Id, Input);

        return(Page());
    }