Exemplo n.º 1
0
        public async Task <int> Update(Client client)
        {
            var clientInfo = await GetInfo(client.ClientId);

            if (clientInfo == null)
            {
                return(-1);
            }

            clientInfo = client;
            Context.Entry(clientInfo).State = EntityState.Modified;
            Context.Entry(clientInfo).Property(x => x.ClientId).IsModified = false;
            return(await Context.SaveChangesAsync());
        }
Exemplo n.º 2
0
        private static Client MapToClient(ClientMeta clientMeta)
        {
            var client = new Client
            {
                ClientId = clientMeta.ClientId,
                IdentityTokenLifetime            = clientMeta.IdentityTokenLifetime,
                ClientName                       = clientMeta.ClientName,
                AbsoluteRefreshTokenLifetime     = clientMeta.AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime              = clientMeta.AccessTokenLifetime,
                AccessTokenType                  = clientMeta.AccessTokenType,
                AllowAccessTokensViaBrowser      = clientMeta.AllowAccessTokensViaBrowser,
                AllowOfflineAccess               = clientMeta.AllowOfflineAccess,
                AllowPlainTextPkce               = clientMeta.AllowPlainTextPkce,
                AllowRememberConsent             = clientMeta.AllowRememberConsent,
                AlwaysIncludeUserClaimsInIdToken = clientMeta.AlwaysIncludeUserClaimsInIdToken,
                AlwaysSendClientClaims           = clientMeta.AlwaysSendClientClaims,
                AuthorizationCodeLifetime        = clientMeta.AuthorizationCodeLifetime,
                BackChannelLogoutSessionRequired = clientMeta.BackChannelLogoutSessionRequired,
                BackChannelLogoutUri             = clientMeta.BackChannelLogoutUri,
                ClientClaimsPrefix               = clientMeta.ClientClaimsPrefix,
                ClientUri        = clientMeta.ClientUri,
                ConsentLifetime  = clientMeta.ConsentLifetime,
                EnableLocalLogin = clientMeta.EnableLocalLogin,
                Enabled          = clientMeta.Enabled,
                FrontChannelLogoutSessionRequired = clientMeta.FrontChannelLogoutSessionRequired,
                FrontChannelLogoutUri             = clientMeta.FrontChannelLogoutUri,
                IncludeJwtId                     = clientMeta.IncludeJwtId,
                LogoUri                          = clientMeta.LogoUri,
                ClientAllowedGrantTypes          = clientMeta.ClientAllowedGrantTypes,
                PairWiseSubjectSalt              = clientMeta.PairWiseSubjectSalt,
                ProtocolType                     = clientMeta.ProtocolType,
                RefreshTokenExpiration           = clientMeta.RefreshTokenExpiration,
                RefreshTokenUsage                = clientMeta.RefreshTokenUsage,
                RequireClientSecret              = clientMeta.RequireClientSecret,
                RequireConsent                   = clientMeta.RequireConsent,
                RequirePkce                      = clientMeta.RequirePkce,
                SlidingRefreshTokenLifetime      = clientMeta.SlidingRefreshTokenLifetime,
                UpdateAccessTokenClaimsOnRefresh = clientMeta.UpdateAccessTokenClaimsOnRefresh,
                UnsignName                       = clientMeta.ClientName.StripVietnameseChars()
            };

            return(client);
        }
Exemplo n.º 3
0
        private IdentityServer4.Models.Client MapToIdentityClient(Client client,
                                                                  List <ClientPostLogoutRedirectUris> listPostLogoutRedirectUris,
                                                                  List <ClientRedirectUris> listClientRedirectUris, List <ClientSecret> listClientSecrets,
                                                                  List <ClientProperty> listClientProperty,
                                                                  List <Domain.Models.ClientClaim> listClaims,
                                                                  List <ClientIdentityProviderRestriction> listIdentityProviderRestrictions,
                                                                  List <ClientAllowedCorsOrigin> listAllowedCorsOrigins,
                                                                  List <ClientAllowedScope> listClientAllowedScopes)
        {
            var propertyDictionary = new Dictionary <string, string>();

            if (listClientProperty.Count > 0)
            {
                listClientProperty.ForEach(x =>
                {
                    propertyDictionary.Add(x.Key, x.Value);
                });
            }

            var identityClient = new IdentityServer4.Models.Client
            {
                ClientId = client.ClientId,
                IdentityTokenLifetime            = client.IdentityTokenLifetime,
                ClientName                       = client.ClientName,
                AbsoluteRefreshTokenLifetime     = client.AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime              = client.AccessTokenLifetime,
                AccessTokenType                  = client.AccessTokenType,
                AllowAccessTokensViaBrowser      = client.AllowAccessTokensViaBrowser,
                AllowOfflineAccess               = client.AllowOfflineAccess,
                AllowPlainTextPkce               = client.AllowPlainTextPkce,
                AllowRememberConsent             = client.AllowRememberConsent,
                AlwaysIncludeUserClaimsInIdToken = client.AlwaysIncludeUserClaimsInIdToken,
                AlwaysSendClientClaims           = client.AlwaysSendClientClaims,
                AuthorizationCodeLifetime        = client.AuthorizationCodeLifetime,
                BackChannelLogoutSessionRequired = client.BackChannelLogoutSessionRequired,
                BackChannelLogoutUri             = client.BackChannelLogoutUri,
                ClientClaimsPrefix               = client.ClientClaimsPrefix,
                ClientUri        = client.ClientUri,
                ConsentLifetime  = client.ConsentLifetime,
                EnableLocalLogin = client.EnableLocalLogin,
                Enabled          = client.Enabled,
                FrontChannelLogoutSessionRequired = client.FrontChannelLogoutSessionRequired,
                FrontChannelLogoutUri             = client.FrontChannelLogoutUri,
                IncludeJwtId                     = client.IncludeJwtId,
                LogoUri                          = client.LogoUri,
                PairWiseSubjectSalt              = client.PairWiseSubjectSalt,
                ProtocolType                     = client.ProtocolType,
                RefreshTokenExpiration           = client.RefreshTokenExpiration,
                RefreshTokenUsage                = client.RefreshTokenUsage,
                RequireClientSecret              = client.RequireClientSecret,
                RequireConsent                   = client.RequireConsent,
                RequirePkce                      = client.RequirePkce,
                SlidingRefreshTokenLifetime      = client.SlidingRefreshTokenLifetime,
                UpdateAccessTokenClaimsOnRefresh = client.UpdateAccessTokenClaimsOnRefresh,
                AllowedGrantTypes                = GetGrantTypes(client.ClientAllowedGrantTypes),
                ClientSecrets                    = listClientSecrets.Select(x => new Secret
                {
                    Value       = x.Value,
                    Description = x.Description,
                    Type        = x.Type,
                    Expiration  = x.Expiration
                }).ToList(),
                PostLogoutRedirectUris       = listPostLogoutRedirectUris.Count > 0 ? listPostLogoutRedirectUris.Select(x => x.Uri).ToList() : new List <string>(),
                RedirectUris                 = listClientRedirectUris.Count > 0 ? listClientRedirectUris.Select(x => x.Uri).ToList() : new List <string>(),
                AllowedCorsOrigins           = listAllowedCorsOrigins.Count > 0 ? listAllowedCorsOrigins.Select(x => x.Domain).ToList() : new List <string>(),
                AllowedScopes                = listClientAllowedScopes.Count > 0 ? listClientAllowedScopes.Distinct().Select(x => x.Scope).ToList() : new List <string>(),
                IdentityProviderRestrictions = listIdentityProviderRestrictions.Count > 0 ? listIdentityProviderRestrictions.Select(x => x.IdentityProviderRestriction).ToList() : new List <string>(),
                Properties = propertyDictionary,
                Claims     = listClaims.Count > 0 ? listClaims.Select(x => new IdentityServer4.Models.ClientClaim(x.ClaimType, x.ClaimValue)).ToList() : new List <IdentityServer4.Models.ClientClaim>()
            };

            return(identityClient);
        }