コード例 #1
0
        private ICollection <string> GetGrantType(GrantTypesEnum grantTypesEnum)
        {
            switch (grantTypesEnum)
            {
            case GrantTypesEnum.Implicit:
                return(GrantTypes.Implicit);

            case GrantTypesEnum.ClientCredentials:
                return(GrantTypes.ClientCredentials);

            case GrantTypesEnum.Code:
                return(GrantTypes.Code);

            case GrantTypesEnum.CodeAndClientCredentials:
                return(GrantTypes.CodeAndClientCredentials);

            case GrantTypesEnum.Hybrid:
                return(GrantTypes.Hybrid);

            case GrantTypesEnum.HybridAndClientCredentials:
                return(GrantTypes.HybridAndClientCredentials);

            case GrantTypesEnum.ImplicitAndClientCredentials:
                return(GrantTypes.ImplicitAndClientCredentials);

            case GrantTypesEnum.ResourceOwnerPassword:
                return(GrantTypes.ResourceOwnerPassword);

            case GrantTypesEnum.ResourceOwnerPasswordAndClientCredentials:
                return(GrantTypes.ResourceOwnerPasswordAndClientCredentials);
            }
            return(null);
        }
コード例 #2
0
        private async Task <Client> CreateNewClient(string clientId, string clientName, GrantTypesEnum grantTypesEnum, List <string> redirectUris, List <string> postLogoutRedirectUris, List <string> allowedScopes, List <string> clientSecrets, bool allowOfflineAccess)
        {
            var newClient = new Client
            {
                ClientId               = clientId,
                ClientName             = clientName,
                ClientSecrets          = GetClientSecrets(clientSecrets),
                AllowedGrantTypes      = GetGrantType(grantTypesEnum),
                RedirectUris           = redirectUris,
                PostLogoutRedirectUris = postLogoutRedirectUris,
                AllowedScopes          = allowedScopes,
                AllowOfflineAccess     = allowOfflineAccess
            };

            _configurationContext.Clients.Add(newClient.ToEntity());
            try
            {
                await _configurationContext.SaveChangesAsync();

                return(newClient);
            }
            catch (Exception)
            {
                return(null);
            }
        }