/// <summary>
 /// Gets all API resources.
 /// </summary>
 /// <returns></returns>
 public async IAsyncEnumerable <ApiResource> GetAllResourcesAsync()
 {
     await foreach (var api in _apiResources.EnumAsync(string.Empty))
     {
         yield return(await ConvertToModelAsync(api));
     }
 }
Beispiel #2
0
 /// <summary>
 /// Gets all identity resources
 /// </summary>
 /// <returns></returns>
 public async IAsyncEnumerable <IdentityResource> GetAllResourcesAsync()
 {
     await foreach (var entity in _identityResources.EnumAsync(string.Empty))
     {
         yield return(await ConvertToModelAsync(entity));
     }
 }
        /// <summary>
        /// Returns all available clients.
        /// </summary>
        /// <returns></returns>
        public async Task <Client[]> GetAllClientsAsync()
        {
            var collection = new List <Client>();

            await foreach (var client in _clients.EnumAsync(ClientEntity.Partition))
            {
                collection.Add(await ConvertToModelAsync(client));
            }

            return(collection.ToArray());
        }
        private async Task <ApiResource> ConvertToModelAsync(ApiResourceEntity entity)
        {
            var resource = new ApiResource
            {
                Enabled     = entity.Enabled,
                Name        = entity.Name,
                DisplayName = entity.DisplayName,
                Description = entity.Description,
            };

            await foreach (var claim in _apiResourceClaims.EnumAsync(entity.Name))
            {
                resource.UserClaims.Add(claim.Claim);
            }

            await foreach (var secret in _apiSecrets.EnumAsync(entity.Name))
            {
                resource.ApiSecrets.Add(new Secret
                {
                    Description = secret.Description,
                    Expiration  = secret.Expiration,
                    Type        = secret.Type,
                    Value       = secret.Value,
                });
            }

            await foreach (var scope in _apiScopes.EnumAsync(entity.Name))
            {
                var apiScope = new Scope
                {
                    Name                    = scope.Scope,
                    DisplayName             = scope.DisplayName,
                    Emphasize               = scope.Emphasize,
                    Required                = scope.Required,
                    ShowInDiscoveryDocument = scope.ShowInDiscoveryDocument,
                };

                await foreach (var claim in _apiScopeClaims.EnumAsync($"{entity.Name}|{apiScope.Name}"))
                {
                    apiScope.UserClaims.Add(claim.Claim);
                }

                resource.Scopes.Add(apiScope);
            }

            return(resource);
        }
        /// <summary>
        /// Gets API resources by scope name.
        /// </summary>
        /// <param name="scopeNames"></param>
        /// <returns></returns>
        public async Task <IEnumerable <ApiResource> > FindResourcesByScopeAsync(IEnumerable <string> scopeNames)
        {
            var dictionary = new Dictionary <string, ApiResource>();

            foreach (var scopeName in scopeNames)
            {
                await foreach (var byScope in _byScopes.EnumAsync(scopeName))
                {
                    var apiName = byScope.Name;
                    if (!dictionary.ContainsKey(apiName))
                    {
                        dictionary.Add(apiName, await FindResourceAsync(apiName));
                    }
                }
            }

            return(dictionary.Values);
        }
Beispiel #6
0
        private async Task <IdentityResource> ConvertToModelAsync(IdentityResourceEntity entity)
        {
            var resource = new IdentityResource
            {
                Enabled     = entity.Enabled,
                Name        = entity.Name,
                DisplayName = entity.DisplayName,
                Description = entity.Description,
            };

            await foreach (var claim in _identityClaims.EnumAsync(entity.Name))
            {
                resource.UserClaims.Add(claim.Claim);
            }

            var converted = resource;

            return(converted);
        }
        private async Task <Client> ConvertToModelAsync(ClientEntity entity)
        {
            var client = new Client
            {
                ClientId                          = entity.ClientId,
                Enabled                           = entity.Enabled,
                ProtocolType                      = entity.ProtocolType,
                RequireClientSecret               = entity.RequireClientSecret,
                ClientName                        = entity.ClientName,
                Description                       = entity.Description,
                ClientUri                         = entity.ClientUri,
                LogoUri                           = entity.LogoUri,
                RequireConsent                    = entity.RequireConsent,
                AllowRememberConsent              = entity.AllowRememberConsent,
                RequirePkce                       = entity.RequirePkce,
                AllowPlainTextPkce                = entity.AllowPlainTextPkce,
                AllowAccessTokensViaBrowser       = entity.AllowAccessTokensViaBrowser,
                FrontChannelLogoutUri             = entity.FrontChannelLogoutUri,
                FrontChannelLogoutSessionRequired = entity.FrontChannelLogoutSessionRequired,
                BackChannelLogoutUri              = entity.BackChannelLogoutUri,
                BackChannelLogoutSessionRequired  = entity.BackChannelLogoutSessionRequired,
                AllowOfflineAccess                = entity.AllowOfflineAccess,
                AlwaysIncludeUserClaimsInIdToken  = entity.AlwaysIncludeUserClaimsInIdToken,
                IdentityTokenLifetime             = entity.IdentityTokenLifetime,
                AccessTokenLifetime               = entity.AccessTokenLifetime,
                AuthorizationCodeLifetime         = entity.AuthorizationCodeLifetime,
                AbsoluteRefreshTokenLifetime      = entity.AbsoluteRefreshTokenLifetime,
                SlidingRefreshTokenLifetime       = entity.SlidingRefreshTokenLifetime,
                ConsentLifetime                   = entity.ConsentLifetime,
                RefreshTokenUsage                 = entity.RefreshTokenUsage,
                UpdateAccessTokenClaimsOnRefresh  = entity.UpdateAccessTokenClaimsOnRefresh,
                RefreshTokenExpiration            = entity.RefreshTokenExpiration,
                AccessTokenType                   = entity.AccessTokenType,
                EnableLocalLogin                  = entity.EnableLocalLogin,
                IncludeJwtId                      = entity.IncludeJwtId,
                AlwaysSendClientClaims            = entity.AlwaysSendClientClaims,
                ClientClaimsPrefix                = entity.ClientClaimsPrefix,
                PairWiseSubjectSalt               = entity.PairWiseSubjectSalt,
                UserSsoLifetime                   = entity.UserSsoLifetime,
                UserCodeType                      = entity.UserCodeType,
                DeviceCodeLifetime                = entity.DeviceCodeLifetime,
            };

            await foreach (var claim in _claims.EnumAsync(entity.ClientId))
            {
                client.Claims.Add(new Claim(claim.Type, claim.Value));
            }

            await foreach (var corsOrigin in _corsOrigins.EnumAsync(client.ClientId))
            {
                client.AllowedCorsOrigins.Add(WebUtility.UrlDecode(corsOrigin.Origin));
            }

            await foreach (var grantType in _grantTypes.EnumAsync(entity.ClientId))
            {
                client.AllowedGrantTypes.Add(grantType.GrantType);
            }

            await foreach (var restriction in _idPRestrictions.EnumAsync(entity.ClientId))
            {
                client.IdentityProviderRestrictions.Add(restriction.Provider);
            }

            await foreach (var redirectUri in _postLogoutRedirectUris.EnumAsync(entity.ClientId))
            {
                client.PostLogoutRedirectUris.Add(WebUtility.UrlDecode(redirectUri.PostLogoutRedirectUri));
            }

            await foreach (var redirectUri in _redirectUris.EnumAsync(entity.ClientId))
            {
                client.RedirectUris.Add(WebUtility.UrlDecode(redirectUri.RedirectUri));
            }

            await foreach (var secret in _secrets.EnumAsync(entity.ClientId))
            {
                client.ClientSecrets.Add(new Secret
                {
                    Description = secret.Description,
                    Expiration  = secret.Expiration,
                    Type        = secret.Type,
                    Value       = secret.Value,
                });
            }

            await foreach (var scope in _scopes.EnumAsync(entity.ClientId))
            {
                client.AllowedScopes.Add(scope.Scope);
            }

            return(client);
        }