internal async Task <Client> CreateImplicitClientAsync(IConfigurationDbContext _configurationContext)
        {
            var newClient = new Client
            {
                ClientId               = ClientId,
                ClientName             = ClientName,
                AllowedGrantTypes      = GrantTypes.Implicit,
                RedirectUris           = RedirectUris.Select(a => a.Trim()).ToList(),
                PostLogoutRedirectUris = PostLogoutRedirectUris.Select(a => a.Trim()).ToList(),
                AllowedScopes          = AllowedScopes
            };

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

                await _configurationContext.SaveChangesAsync();

                return(newClient);
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#2
0
        public async Task <Client> UpdateClientAsync(IConfigurationDbContext _configurationContext)
        {
            var updateClient = await _configurationContext.Clients.Include(a => a.AllowedScopes).Include(a => a.RedirectUris).Include(a => a.PostLogoutRedirectUris).Include(a => a.AllowedGrantTypes).Where(a => a.Id == id).FirstOrDefaultAsync();

            var newClientModel = new Client
            {
                ClientName             = ClientName,
                RedirectUris           = RedirectUris.Select(a => a.Trim()).ToList(),
                PostLogoutRedirectUris = PostLogoutRedirectUris.Select(a => a.Trim()).ToList(),
                AllowedScopes          = AllowedScopes
            }.ToEntity();

            updateClient.ClientName = newClientModel.ClientName;
            updateClient.RedirectUris.Clear();
            updateClient.RedirectUris = newClientModel.RedirectUris;

            updateClient.PostLogoutRedirectUris.Clear();
            updateClient.PostLogoutRedirectUris = newClientModel.PostLogoutRedirectUris;

            updateClient.AllowedScopes.Clear();
            updateClient.AllowedScopes = newClientModel.AllowedScopes;

            try
            {
                _configurationContext.Clients.Update(updateClient);

                await _configurationContext.SaveChangesAsync();

                return(updateClient.ToModel());
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#3
0
 public void ParseUrls()
 {
     RedirectUris           = RedirectUris.Select(x => x.RemoveTrailingSlashIfNeeded()).ToArray();
     AllowedCorsOrigins     = AllowedCorsOrigins.Select(x => x.RemoveTrailingSlashIfNeeded()).ToArray();
     FrontChannelLogoutUri  = FrontChannelLogoutUri.RemoveTrailingSlashIfNeeded();
     PostLogoutRedirectUris = PostLogoutRedirectUris.Select(x => x.RemoveTrailingSlashIfNeeded()).ToArray();
 }
示例#4
0
 public void UpdateEntity(IdentityServer4.EntityFramework.Entities.Client entity)
 {
     entity.Enabled                          = Enabled;
     entity.ClientId                         = ClientId;
     entity.ProtocolType                     = ProtocolType;
     entity.RequireClientSecret              = RequireClientSecret;
     entity.ClientName                       = ClientName;
     entity.Description                      = Description;
     entity.ClientUri                        = ClientUri;
     entity.LogoUri                          = LogoUri;
     entity.RequireConsent                   = RequireConsent;
     entity.AllowRememberConsent             = AllowRememberConsent;
     entity.AlwaysIncludeUserClaimsInIdToken = AlwaysIncludeUserClaimsInIdToken;
     entity.AllowedGrantTypes                = AllowedGrantTypes.Select(x => new ClientGrantType
     {
         GrantType = x,
     }).ToList();
     entity.RequirePkce                 = RequirePkce;
     entity.AllowPlainTextPkce          = AllowPlainTextPkce;
     entity.AllowAccessTokensViaBrowser = AllowAccessTokensViaBrowser;
     entity.RedirectUris                = RedirectUris.Select(x => new ClientRedirectUri
     {
         RedirectUri = x,
     }).ToList();
     entity.PostLogoutRedirectUris = PostLogoutRedirectUris.Select(x => new ClientPostLogoutRedirectUri
     {
         PostLogoutRedirectUri = x,
     }).ToList();
     entity.FrontChannelLogoutUri             = FrontChannelLogoutUri;
     entity.FrontChannelLogoutSessionRequired = FrontChannelLogoutSessionRequired;
     entity.BackChannelLogoutUri             = BackChannelLogoutUri;
     entity.BackChannelLogoutSessionRequired = BackChannelLogoutSessionRequired;
     entity.AllowOfflineAccess = AllowOfflineAccess;
     entity.AllowedScopes      = AllowedScopes.Select(x => new ClientScope
     {
         Scope = x,
     }).ToList();
     entity.IdentityTokenLifetime            = IdentityTokenLifetime;
     entity.AccessTokenLifetime              = AccessTokenLifetime;
     entity.AuthorizationCodeLifetime        = AuthorizationCodeLifetime;
     entity.ConsentLifetime                  = ConsentLifetime;
     entity.AbsoluteRefreshTokenLifetime     = AbsoluteRefreshTokenLifetime;
     entity.SlidingRefreshTokenLifetime      = SlidingRefreshTokenLifetime;
     entity.RefreshTokenUsage                = (int)RefreshTokenUsage;
     entity.UpdateAccessTokenClaimsOnRefresh = UpdateAccessTokenClaimsOnRefresh;
     entity.RefreshTokenExpiration           = (int)RefreshTokenExpiration;
     entity.AccessTokenType                  = (int)AccessTokenType;
     entity.EnableLocalLogin                 = EnableLocalLogin;
     entity.IdentityProviderRestrictions     = IdentityProviderRestrictions.Select(x => new ClientIdPRestriction
     {
         Provider = x,
     }).ToList();
     entity.IncludeJwtId           = IncludeJwtId;
     entity.AlwaysSendClientClaims = AlwaysSendClientClaims;
     entity.ClientClaimsPrefix     = ClientClaimsPrefix;
     entity.PairWiseSubjectSalt    = PairWiseSubjectSalt;
     entity.AllowedCorsOrigins     = AllowedCorsOrigins.Select(x => new ClientCorsOrigin
     {
         Origin = x,
     }).ToList();
     entity.UserSsoLifetime    = UserSsoLifetime;
     entity.UserCodeType       = UserCodeType;
     entity.DeviceCodeLifetime = DeviceCodeLifetime;
 }