public ConsentViewModel(ConsentInputModel model, string consentId, ConsentRequest request, Client client, IEnumerable<Scope> scopes, ILocalizationService localization)
        {
            RememberConsent = model?.RememberConsent ?? true;
            ScopesConsented = model?.ScopesConsented ?? Enumerable.Empty<string>();

            ConsentId = consentId;

            ClientName = client.ClientName;
            ClientUrl = client.ClientUri;
            ClientLogoUrl = client.LogoUri;
            AllowRememberConsent = client.AllowRememberConsent;

            IdentityScopes = scopes.Where(x => x.Type == ScopeType.Identity).Select(x => new ScopeViewModel(localization, x, ScopesConsented.Contains(x.Name) || model == null)).ToArray();
            ResourceScopes = scopes.Where(x => x.Type == ScopeType.Resource).Select(x => new ScopeViewModel(localization, x, ScopesConsented.Contains(x.Name) || model == null)).ToArray();
        }
        public async Task ProcessAsync_consent_missing_consent_data_should_return_error_page()
        {
            var parameters = new NameValueCollection()
            {
                { "client_id", "client" },
                { "nonce", "some_nonce" },
                { "scope", "api1 api2" }
            };
            var request = new ConsentRequest(parameters, _user.GetSubjectId());

            _mockUserConsentResponseMessageStore.Messages.Add(request.Id, new Message <ConsentResponse>(null));

            _mockUserSession.User = _user;

            _context.Request.Method      = "GET";
            _context.Request.Path        = new PathString("/connect/authorize/callback");
            _context.Request.QueryString = new QueryString("?" + parameters.ToQueryString());

            var result = await _subject.ProcessAsync(_context);

            result.Should().BeOfType <AuthorizeResult>();
            ((AuthorizeResult)result).Response.IsError.Should().BeTrue();
        }
コード例 #3
0
        public ConsentRequest Insert(ConsentRequest req)
        {
            try
            {
                if (this.GetByEmailAddress(req.EmailAddress) != null)
                {
                    throw new InvalidOperationException("Email address " + req.EmailAddress + " already exists");
                }

                Guid id;
                do
                {
                    id = Guid.NewGuid();
                } while (_liteDb.GetCollection <ConsentRequest>("ConsentRequest").Count(Query.EQ("_id", id)) > 0);

                ConsentRequest newreq = new ConsentRequest()
                {
                    Id             = id,
                    FullName       = req.FullName,
                    EmailAddress   = req.EmailAddress,
                    Template       = req.Template,
                    Status         = req.Status,
                    SubmissionDate = null,
                };
                if (_liteDb.GetCollection <ConsentRequest>("ConsentRequest").Insert(newreq) != null)
                {
                    return(newreq);
                }
                else
                {
                    return(null);
                }
            } catch
            {
                return(null);
            }
        }
コード例 #4
0
        /// <summary>
        /// Set the consent details for the nominated key.
        /// </summary>
        /// <param name="key">The consent key.</param>
        /// <param name="member">The consent member we are updating on behalf of.</param>
        /// <param name="scopes">The consent scopes being granted. If null, all scopes are granted.</param>
        /// <param name="authorizedMembers">The members authorized to access this consent. If null, all members are authorized.</param>
        /// <returns>The new consent details.</returns>
        /// <exception cref="SerializationException">Unable process the service response.</exception>
        /// <exception cref="LogicTokenProviderException">Unable to issue an authorization token.</exception>
        /// <exception cref="ConsentValidationException">Invalid consent request.</exception>
        /// <exception cref="ConsentConfigurationException">Invalid consent configuration details.</exception>
        public async Task <ConsentInstance> SaveConsentAsync(string key, string member, IList <string> scopes = null, IList <string> authorizedMembers = null)
        {
            var client = this.CreateClient();

            try
            {
                var request = new ConsentRequest
                {
                    Member            = member,
                    Scopes            = scopes,
                    AuthorizedMembers = authorizedMembers,
                };

                var response = await client.SaveConsentWithHttpMessagesAsync(
                    subscriptionId : this.options.SubscriptionId,
                    consentGroupId : this.options.ConsentGroupId,
                    key : key,
                    request : request).ConfigureAwait(false);

                switch (response.Response.StatusCode)
                {
                case System.Net.HttpStatusCode.OK:
                case System.Net.HttpStatusCode.Created:
                    return((ConsentInstance)response.Body);

                case System.Net.HttpStatusCode.BadRequest:
                    throw new ConsentValidationException(response.Body as IDictionary <string, IList <string> >);

                default:
                    throw new ConsentConfigurationException("Invalid configuration provided to access consent service", response.Body as string);
                }
            }
            catch (ValidationException ex)
            {
                throw new ConsentValidationException(ex.Message, ex);
            }
        }
コード例 #5
0
        public async Task ProcessAsync_no_consent_message_should_return_redirect_for_consent()
        {
            _stubInteractionGenerator.Response.IsConsent = true;

            var parameters = new NameValueCollection()
            {
                { "client_id", "client" },
                { "nonce", "some_nonce" },
                { "scope", "api1 api2" }
            };
            var request = new ConsentRequest(parameters, _user.GetSubjectId());

            _mockUserConsentResponseMessageStore.Messages.Add(request.Id, null);

            _mockUserSession.User = _user;

            _context.Request.Method      = "GET";
            _context.Request.Path        = new PathString("/connect/authorize/callback");
            _context.Request.QueryString = new QueryString("?" + parameters.ToQueryString());

            var result = await _subject.ProcessAsync(_context);

            result.Should().BeOfType <ConsentPageResult>();
        }
コード例 #6
0
        public async Task ProcessAuthorizeWithConsentAsync_valid_consent_message_should_cleanup_consent_cookie()
        {
            var parameters = new NameValueCollection
            {
                { "client_id", "client" },
                { "nonce", "some_nonce" },
                { "scope", "api1 api2" }
            };
            var request = new ConsentRequest(parameters, _user.GetSubjectId());

            _mockUserConsentResponseMessageStore.Messages.Add(request.Id, new Message <ConsentResponse>(new ConsentResponse {
                ScopesConsented = new[] { "api1", "api2" }
            }));

            _context.SetUser(_user);

            _context.Request.Method      = "GET";
            _context.Request.Path        = new PathString("/connect/authorize/consent");
            _context.Request.QueryString = new QueryString("?" + parameters.ToQueryString());

            var result = await _subject.ProcessAuthorizeAfterConsentAsync(_context);

            _mockUserConsentResponseMessageStore.Messages.Count.Should().Be(0);
        }
コード例 #7
0
        internal async Task <IEndpointResult> ProcessAuthorizeAfterConsentAsync(IdentityServerContext context)
        {
            _logger.LogInformation("Start authorize request (after consent)");

            var user = await _context.GetIdentityServerUserAsync();

            if (user == null)
            {
                _logger.LogError("User is not authenticated.");
                return(await ErrorPageAsync(ErrorTypes.User, nameof(Messages.UnexpectedError), null));
            }

            var parameters     = context.HttpContext.Request.Query.AsNameValueCollection();
            var consentRequest = new ConsentRequest(parameters, user.GetSubjectId());

            var consent = await _consentResponseStore.ReadAsync(consentRequest.Id);

            if (consent == null)
            {
                _logger.LogError("consent message is missing.");
                return(await ErrorPageAsync(ErrorTypes.User, nameof(Messages.UnexpectedError), null));
            }
            if (consent.Data == null)
            {
                _logger.LogError("consent message is missing Consent data.");
                return(await ErrorPageAsync(ErrorTypes.User, nameof(Messages.UnexpectedError), null));
            }

            var result = await ProcessAuthorizeRequestAsync(parameters, user, consent.Data);

            await _consentResponseStore.DeleteAsync(consentRequest.Id);

            _logger.LogInformation("End Authorize Request. Result type: {0}", result?.GetType().ToString() ?? "-none-");

            return(result);
        }
コード例 #8
0
        void IConsentService.Consent(ConsentRequest request)
        {
            queuedRequests.Enqueue(request);

            Console.WriteLine("Request received for customer {0}. {1} in queue.", request.Customer, QueuedRequests);
        }
コード例 #9
0
    internal async Task <IEndpointResult> ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, bool checkConsentResponse = false)
    {
        if (user != null)
        {
            Logger.LogDebug("User in authorize request: {subjectId}", user.GetSubjectId());
        }
        else
        {
            Logger.LogDebug("No user present in authorize request");
        }

        if (checkConsentResponse && _authorizationParametersMessageStore != null)
        {
            var messageStoreId = parameters[Constants.AuthorizationParamsStore.MessageStoreIdParameterName];
            var entry          = await _authorizationParametersMessageStore.ReadAsync(messageStoreId);

            parameters = entry?.Data.FromFullDictionary() ?? new NameValueCollection();

            await _authorizationParametersMessageStore.DeleteAsync(messageStoreId);
        }

        // validate request
        var result = await _validator.ValidateAsync(parameters, user);

        if (result.IsError)
        {
            return(await CreateErrorResultAsync(
                       "Request validation failed",
                       result.ValidatedRequest,
                       result.Error,
                       result.ErrorDescription));
        }

        string consentRequestId = null;

        try
        {
            Message <ConsentResponse> consent = null;

            if (checkConsentResponse)
            {
                var consentRequest = new ConsentRequest(result.ValidatedRequest.Raw, user?.GetSubjectId());
                consentRequestId = consentRequest.Id;
                consent          = await _consentResponseStore.ReadAsync(consentRequestId);

                if (consent != null && consent.Data == null)
                {
                    return(await CreateErrorResultAsync("consent message is missing data"));
                }
            }

            var request = result.ValidatedRequest;
            LogRequest(request);

            // determine user interaction
            var interactionResult = await _interactionGenerator.ProcessInteractionAsync(request, consent?.Data);

            if (interactionResult.IsError)
            {
                return(await CreateErrorResultAsync("Interaction generator error", request, interactionResult.Error, interactionResult.ErrorDescription, false));
            }
            if (interactionResult.IsLogin)
            {
                return(new LoginPageResult(request));
            }
            if (interactionResult.IsConsent)
            {
                return(new ConsentPageResult(request));
            }
            if (interactionResult.IsRedirect)
            {
                return(new CustomRedirectResult(request, interactionResult.RedirectUrl));
            }

            var response = await _authorizeResponseGenerator.CreateResponseAsync(request);

            await RaiseResponseEventAsync(response);

            LogResponse(response);

            return(new AuthorizeResult(response));
        }
        finally
        {
            if (consentRequestId != null)
            {
                await _consentResponseStore.DeleteAsync(consentRequestId);
            }
        }
    }
コード例 #10
0
 public bool Update(ConsentRequest req)
 {
     return(_requests.TryAdd(req.Id, req));
 }
コード例 #11
0
 /// <summary>
 /// Create or update the details of consent
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='subscriptionId'>
 /// The subscription with access to the consent group
 /// </param>
 /// <param name='consentGroupId'>
 /// The consent group to update
 /// </param>
 /// <param name='key'>
 /// The consent key being updated
 /// </param>
 /// <param name='request'>
 /// The details of consent being granted
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> SaveConsentAsync(this IInternalClient operations, System.Guid subscriptionId, System.Guid consentGroupId, string key, ConsentRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.SaveConsentWithHttpMessagesAsync(subscriptionId, consentGroupId, key, request, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #12
0
 /// <summary>
 /// Create or update the details of consent
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='subscriptionId'>
 /// The subscription with access to the consent group
 /// </param>
 /// <param name='consentGroupId'>
 /// The consent group to update
 /// </param>
 /// <param name='key'>
 /// The consent key being updated
 /// </param>
 /// <param name='request'>
 /// The details of consent being granted
 /// </param>
 public static object SaveConsent(this IInternalClient operations, System.Guid subscriptionId, System.Guid consentGroupId, string key, ConsentRequest request)
 {
     return(operations.SaveConsentAsync(subscriptionId, consentGroupId, key, request).GetAwaiter().GetResult());
 }
コード例 #13
0
 public void Post(ConsentRequest request)
 {
     StatsDatabase.Instance?.Consent(request);
 }
コード例 #14
0
 /// <inheritdoc/>
 public ClientResponse <ConsentResponse> CreateConsent(Guid?consentId, ConsentRequest request)
 {
     return(client.CreateConsentAsync(consentId, request).GetAwaiter().GetResult());
 }