Esempio n. 1
0
        /// <summary>
        /// Returns a list of scopes from a concatenate list of scopes separated by whitespaces.
        /// </summary>
        /// <param name="concatenateListOfScopes"></param>
        /// <returns>List of scopes</returns>
        private async Task <ICollection <Scope> > GetScopes(string concatenateListOfScopes)
        {
            var result     = new List <Scope>();
            var scopeNames = _parameterParserHelper.ParseScopes(concatenateListOfScopes);

            return(await _scopeRepository.SearchByNamesAsync(scopeNames));
        }
        private async Task <IEnumerable <Scope> > GetScopes(string concatenateListOfScopes)
        {
            var result     = new List <Scope>();
            var scopeNames = concatenateListOfScopes.Split(' ');

            return(await _scopeRepository.SearchByNamesAsync(scopeNames));
        }
Esempio n. 3
0
        public async Task <bool> Execute(UpdateClientParameter updateClientParameter)
        {
            if (updateClientParameter == null)
            {
                throw new ArgumentNullException(nameof(updateClientParameter));
            }

            if (string.IsNullOrWhiteSpace(updateClientParameter.ClientId))
            {
                throw new IdentityServerManagerException(ErrorCodes.InvalidParameterCode, string.Format(ErrorDescriptions.MissingParameter, "client_id"));
            }

            _managerEventSource.StartToUpdateClient(JsonConvert.SerializeObject(updateClientParameter));
            var existedClient = await _clientRepository.GetClientByIdAsync(updateClientParameter.ClientId);

            if (existedClient == null)
            {
                throw new IdentityServerManagerException(ErrorCodes.InvalidParameterCode, string.Format(ErrorDescriptions.TheClientDoesntExist, updateClientParameter.ClientId));
            }

            SimpleIdentityServer.Core.Common.Models.Client client = null;
            try
            {
                client = _generateClientFromRegistrationRequest.Execute(updateClientParameter);
            }
            catch (IdentityServerException ex)
            {
                throw new IdentityServerManagerException(ex.Code, ex.Message);
            }

            client.ClientId      = existedClient.ClientId;
            client.AllowedScopes = updateClientParameter.AllowedScopes == null
                ? new List <Scope>()
                : updateClientParameter.AllowedScopes.Select(s => new Scope
            {
                Name = s
            }).ToList();
            var existingScopes = await _scopeRepository.SearchByNamesAsync(client.AllowedScopes.Select(s => s.Name));

            var notSupportedScopes = client.AllowedScopes.Where(s => !existingScopes.Any(sc => sc.Name == s.Name)).Select(s => s.Name);

            if (notSupportedScopes.Any())
            {
                throw new IdentityServerManagerException(ErrorCodes.InvalidParameterCode, string.Format(ErrorDescriptions.TheScopesDontExist, string.Join(",", notSupportedScopes)));
            }

            var result = await _clientRepository.UpdateAsync(client);

            if (!result)
            {
                throw new IdentityServerManagerException(ErrorCodes.InternalErrorCode, ErrorDescriptions.TheClientCannotBeUpdated);
            }

            _managerEventSource.FinishToUpdateClient(JsonConvert.SerializeObject(updateClientParameter));
            return(result);
        }
Esempio n. 4
0
        private async Task <Dictionary <string, string> > GetClaimsFromRequestedScopes(IEnumerable <string> scopes, ClaimsPrincipal claimsPrincipal)
        {
            var result         = new Dictionary <string, string>();
            var returnedScopes = await _scopeRepository.SearchByNamesAsync(scopes);

            foreach (var returnedScope in returnedScopes)
            {
                result.AddRange(GetClaims(returnedScope.Claims, claimsPrincipal));
            }

            return(result);
        }