Пример #1
0
        /// <summary>
        /// Updates the consent asynchronous.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="scopes">The scopes.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// client
        /// or
        /// subject
        /// </exception>
        public virtual async Task UpdateConsentAsync(ClaimsPrincipal subject, Client client, IEnumerable <string> scopes)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (subject == null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            if (client.AllowRememberConsent)
            {
                var subjectId = subject.GetSubjectId();
                var clientId  = client.ClientId;

                if (scopes != null && scopes.Any())
                {
                    var consent = new Consent
                    {
                        SubjectId = subjectId,
                        ClientId  = clientId,
                        Scopes    = scopes
                    };
                    await _grants.StoreUserConsentAsync(consent);
                }
                else
                {
                    await _grants.RemoveUserConsentAsync(subjectId, clientId);
                }
            }
        }