public bool AreScopesValid(IEnumerable <string> requestedScopes, IEnumerable <Scope> availableScopes)
        {
            foreach (var requestedScope in requestedScopes)
            {
                var scopeDetail = availableScopes.FirstOrDefault(s => s.Name == requestedScope);

                if (scopeDetail == null)
                {
                    Logger.ErrorFormat("Invalid scope: {0}", requestedScope);
                    return(false);
                }

                if (scopeDetail.IsOpenIdScope)
                {
                    ContainsOpenIdScopes = true;
                }
                else
                {
                    ContainsResourceScopes = true;
                }

                GrantedScopes.Add(scopeDetail);
            }

            RequestedScopes.AddRange(GrantedScopes);

            return(true);
        }
        public async Task <bool> AreScopesValidAsync(IEnumerable <string> requestedScopes)
        {
            var requestedScopesArray = requestedScopes as string[] ?? requestedScopes.ToArray();
            var availableScopesArray = (await _store.FindEnabledScopesAsync(requestedScopesArray)).ToArray();

            foreach (var requestedScope in requestedScopesArray)
            {
                var scopeDetail = availableScopesArray.FirstOrDefault(s => s.Name == requestedScope);

                if (scopeDetail == null)
                {
                    _logger.LogError("Invalid scope: {requestedScope}", requestedScope);
                    return(false);
                }

                if (scopeDetail.Enabled == false)
                {
                    _logger.LogError("Scope disabled: {requestedScope}", requestedScope);
                    return(false);
                }

                if (scopeDetail.Type == ScopeType.Identity)
                {
                    ContainsOpenIdScopes = true;
                }
                else
                {
                    ContainsResourceScopes = true;
                }

                GrantedScopes.Add(scopeDetail);
            }

            if (requestedScopesArray.Contains(Constants.StandardScopes.OfflineAccess))
            {
                ContainsOfflineAccessScope = true;
            }

            RequestedScopes.AddRange(GrantedScopes);

            return(true);
        }
        public bool AreScopesValid(IEnumerable <string> requestedScopes, IEnumerable <Scope> availableScopes)
        {
            foreach (var requestedScope in requestedScopes)
            {
                var scopeDetail = availableScopes.FirstOrDefault(s => s.Name == requestedScope);

                if (scopeDetail == null)
                {
                    Logger.ErrorFormat("Invalid scope: {0}", requestedScope);
                    return(false);
                }

                if (scopeDetail.Enabled == false)
                {
                    Logger.ErrorFormat("Scope disabled: {0}", requestedScope);
                    return(false);
                }

                if (scopeDetail.Type == ScopeType.Identity)
                {
                    ContainsOpenIdScopes = true;
                }
                else
                {
                    ContainsResourceScopes = true;
                }

                GrantedScopes.Add(scopeDetail);
            }

            if (requestedScopes.Contains(Constants.StandardScopes.OfflineAccess))
            {
                ContainsOfflineAccessScope = true;
            }

            RequestedScopes.AddRange(GrantedScopes);

            return(true);
        }