Пример #1
0
        public SharedModels.Client GetClientByClientId(string clientId)
        {
            var clientModel = _applicationClientRepository.GetClientByClientId(clientId);

            SharedModels.Client client = MapDaltoBll(clientModel);
            return(client);
        }
Пример #2
0
        public void UpdateClient(SharedModels.Client client)
        {
            IdentityServer4.EntityFramework.Entities.Client clientModel = MapBllToDal(client);

            var deleteobj = _applicationClientRepository.GetClientByClientId(clientModel.ClientId);

            _applicationClientRepository.DeleteClient(deleteobj);
            _applicationClientRepository.AddClient(clientModel);
            //_applicationClientRepository.UpdateClient(clientModel);
        }
Пример #3
0
 public void AddClient(SharedModels.Client client)
 {
     IdentityServer4.EntityFramework.Entities.Client clientModel = MapBllToDal(client);
     try {
         _applicationClientRepository.AddClient(clientModel);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #4
0
        public List <SharedModels.Client> GetClients()
        {
            var list   = new List <SharedModels.Client>();
            var result = _applicationClientRepository.GetClients();

            foreach (IdentityServer4.EntityFramework.Entities.Client clientModel in result)
            {
                SharedModels.Client client = MapDaltoBll(clientModel);
                list.Add(client);
            }
            return(list);
        }
Пример #5
0
        private IdentityServer4.EntityFramework.Entities.Client MapBllToDal(SharedModels.Client client)
        {
            IdentityServer4.Models.Client clientModelIds4 = new IdentityServer4.Models.Client();

            clientModelIds4.ClientName            = client.ClientName;
            clientModelIds4.ClientUri             = client.ClientUri;
            clientModelIds4.ClientId              = client.ClientId;
            clientModelIds4.FrontChannelLogoutUri = client.FrontChannelLogoutUrl;

            if (client.ClientSecret != null)
            {
                IdentityServer4.Models.Secret secret = new IdentityServer4.Models.Secret(client.ClientSecret.Sha256());
                secret.Type = "SharedSecret";
                clientModelIds4.ClientSecrets = new List <IdentityServer4.Models.Secret>();
                clientModelIds4.ClientSecrets.Add(secret);
            }


            clientModelIds4.AllowedGrantTypes = new List <string>();
            client.GrantType = client.GrantType.Replace(" ", "_");
            clientModelIds4.AllowedGrantTypes.Add(client.GrantType);

            if (client.ClientProperty != null)
            {
                string key = "ApplicationType";
                clientModelIds4.Properties = new Dictionary <string, string>();
                clientModelIds4.Properties.Add(key, client.ClientProperty);
            }

            clientModelIds4.AllowedScopes = new List <string>();
            foreach (string scope in client.AllowedScopes)
            {
                var replacedScope = scope.Replace(" ", "_");
                clientModelIds4.AllowedScopes.Add(replacedScope);
            }

            clientModelIds4.RedirectUris = new List <string>();
            foreach (string redirctUri in client.RedirectUrls)
            {
                clientModelIds4.RedirectUris.Add(redirctUri);
            }

            clientModelIds4.PostLogoutRedirectUris = new List <string>();
            clientModelIds4.PostLogoutRedirectUris.Add(client.PostLogoutUrl);

            return(clientModelIds4.ToEntity());
        }
Пример #6
0
        private SharedModels.Client MapDaltoBll(IdentityServer4.EntityFramework.Entities.Client clientModel)
        {
            IdentityServer4.Models.Client clientModelIds4 = new IdentityServer4.Models.Client();
            clientModelIds4 = clientModel.ToModel();

            SharedModels.Client client = new SharedModels.Client();
            client.ClientId              = clientModelIds4.ClientId;
            client.ClientName            = clientModelIds4.ClientName;
            client.ClientUri             = clientModelIds4.ClientUri;
            client.FrontChannelLogoutUrl = clientModelIds4.FrontChannelLogoutUri;

            if (clientModelIds4.ClientSecrets.Count > 0)
            {
                foreach (IdentityServer4.Models.Secret secret in clientModelIds4.ClientSecrets)
                {
                    client.ClientSecret = secret.Value;
                }
            }

            if (clientModelIds4.AllowedGrantTypes.Count > 0)
            {
                foreach (string grantType in clientModelIds4.AllowedGrantTypes)
                {
                    client.GrantType = grantType;
                }
            }

            if (clientModelIds4.Properties.Count > 0)
            {
                foreach (var property in clientModelIds4.Properties)
                {
                    client.ClientProperty = property.Value;
                }
            }

            if (clientModelIds4.RedirectUris.Count > 0)
            {
                client.RedirectUrls = new string[clientModel.RedirectUris.Count];
                int i = 0;
                foreach (string uri in clientModelIds4.RedirectUris)
                {
                    client.RedirectUrls[i] = uri;
                    i++;
                }
            }

            if (clientModelIds4.PostLogoutRedirectUris.Count > 0)
            {
                foreach (string uri in clientModelIds4.PostLogoutRedirectUris)
                {
                    client.PostLogoutUrl = uri;
                }
            }

            if (clientModelIds4.AllowedScopes.Count > 0)
            {
                client.AllowedScopes = new string[clientModel.AllowedScopes.Count];
                int i = 0;
                foreach (string scope in clientModelIds4.AllowedScopes)
                {
                    client.AllowedScopes[i] = scope;
                    i++;
                }
            }
            return(client);
        }