コード例 #1
0
        public async Task <Client> FindClientByIdAsync(string clientId)
        {
            var clientManager = factory.GetClientManager();

            var apiClient = factory.GetClientManager().CreateContentsClient <ClientEntity, ClientData>("clients");

            var query = new ContentQuery
            {
                Filter = $"data/clientId/iv eq '{clientId}'"
            };

            var clients = await apiClient.GetAsync(query, context : Context.Build());

            var client = clients.Items.FirstOrDefault();

            if (client == null)
            {
                return(null);
            }

            var scopes = new HashSet <string>(client.Data.AllowedScopes.OrDefault())
            {
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile,
                IdentityServerConstants.StandardScopes.Email,
                DefaultResources.Permissions.Scope
            };

            return(new Client
            {
                AllowAccessTokensViaBrowser = true,
                AllowedCorsOrigins = client.Data.AllowedCorsOrigins.OrDefault(),
                AllowedGrantTypes = client.Data.AllowedGrantTypes.OrDefault(),
                AllowedScopes = scopes,
                AllowOfflineAccess = client.Data.AllowOfflineAccess,
                ClientId = clientId,
                ClientName = client.Data.ClientName,
                ClientSecrets = client.Data.ClientSecrets.ToSecrets(),
                ClientUri = client.Data.ClientUri,
                LogoUri = clientManager.GenerateImageUrl(client.Data.Logo),
                PostLogoutRedirectUris = client.Data.PostLogoutRedirectUris.OrDefault(),
                RedirectUris = client.Data.RedirectUris.OrDefault(),
                RequireConsent = client.Data.RequireConsent
            });
        }
コード例 #2
0
        public async Task <Client> FindClientByIdAsync(string clientId)
        {
            var clientManager = factory.GetClientManager();

            var clients = await GetClientsAsync();

            var client = clients.Items.FirstOrDefault(x => x.Data.ClientId == clientId);

            if (client == null)
            {
                return(null);
            }

            return(client.ToClient(clientManager));
        }
コード例 #3
0
        private Task <(List <IdentityResource> IdentityResources, List <ApiResource> ApiResources)> GetResourcesAsync()
        {
            return(GetOrAddAsync(nameof(ResourceStore), async() =>
            {
                var clientManager = factory.GetClientManager();

                var taskForApiResources = GetApiResourcesAsync(clientManager);
                var taskForIdentityResources = GetIdentityResourcesAsync(clientManager);

                await Task.WhenAll(taskForApiResources, taskForIdentityResources);

                var identityResources = taskForIdentityResources.Result.Items.Select(x =>
                {
                    var identityResource = new IdentityResource(x.Data.Name, x.Data.DisplayName, x.Data.UserClaims.OrDefault())
                    {
                        Description = x.Data.Description,
                        Emphasize = true,
                        Required = x.Data.Required
                    };

                    return identityResource;
                }).ToList();

                identityResources.Add(new IdentityResources.OpenId());
                identityResources.Add(new IdentityResources.Profile());
                identityResources.Add(new IdentityResources.Email());
                identityResources.Add(new IdentityResources.Phone());
                identityResources.Add(new DefaultResources.Permissions(localizer));

                var apiResources = taskForApiResources.Result.Items.Select(x =>
                {
                    var apiResource = new ApiResource(x.Data.Name, x.Data.DisplayName, x.Data.UserClaims.OrDefault())
                    {
                        Description = x.Data.Description
                    };

                    apiResource.Scopes.First().Description = x.Data.Description;

                    return apiResource;
                }).ToList();

                return (identityResources, apiResources);
            }));
コード例 #4
0
        public Task <SettingsData> GetSettingsAsync()
        {
            return(GetOrAddAsync(nameof(SettingsProvider), async() =>
            {
                var apiClient =
                    factory.GetClientManager()
                    .CreateContentsClient <SettingsEntity, SettingsData>("settings");

                var settings = await apiClient.GetAsync(context: Context.Build());

                var result = settings.Items.FirstOrDefault()?.Data ?? new SettingsData();

                foreach (var property in result.GetType().GetProperties())
                {
                    if (property.GetValue(result) == null)
                    {
                        property.SetValue(result, property.GetValue(defaults.Value));
                    }
                }

                return result;
            }));
        }