public async Task InvalidSubjectAndClientShouldBeNull()
        {
            await _setup;
            var   results = await _store.LoadAsync("Invalid", "Invalid");

            Assert.Null(results);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if consent is required.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="subject">The user.</param>
        /// <param name="scopes">The scopes.</param>
        /// <returns>Boolean if consent is required.</returns>
        public virtual async Task <bool> RequiresConsentAsync(Client client, ClaimsPrincipal subject, IEnumerable <string> scopes)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }

            if (!client.RequireConsent)
            {
                return(false);
            }

            // TODO: validate that this is a correct statement
            if (!client.AllowRememberConsent)
            {
                return(true);
            }

            if (scopes == null || !scopes.Any())
            {
                return(false);
            }

            // we always require consent for offline access if
            // the client has not disabled RequireConsent
            if (scopes.Contains(Constants.StandardScopes.OfflineAccess))
            {
                return(true);
            }

            var consent = await _store.LoadAsync(subject.GetSubjectId(), client.ClientId);

            if (consent != null && consent.Scopes != null)
            {
                var intersect = scopes.Intersect(consent.Scopes);
                return(!(scopes.Count() == intersect.Count()));
            }

            return(true);
        }
        public async Task <bool> RequiresConsentAsync(Client client, ClaimsPrincipal user, IEnumerable <string> scopes)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (!client.RequireConsent)
            {
                return(false);
            }

            // TODO: validate that this is a correct statement
            if (!client.AllowRememberConsent)
            {
                return(true);
            }

            if (scopes == null || !scopes.Any())
            {
                return(false);
            }

            var consent = await _store.LoadAsync(user.GetSubjectId(), client.ClientId);

            if (consent != null && consent.Scopes != null)
            {
                var intersect = scopes.Intersect(consent.Scopes);
                return(!(scopes.Count() == intersect.Count()));
            }

            return(true);
        }