public virtual async Task <ClientDto> CreateAsync(ClientCreateDto clientCreate) { var clientIdExists = await ClientRepository.CheckClientIdExistAsync(clientCreate.ClientId); if (clientIdExists) { throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ClientIdExisted, clientCreate.ClientId]); } var client = new Client(GuidGenerator.Create(), clientCreate.ClientId) { ClientName = clientCreate.ClientName, Description = clientCreate.Description }; foreach (var inputGrantType in clientCreate.AllowedGrantTypes) { client.AddGrantType(inputGrantType.GrantType); } client = await ClientRepository.InsertAsync(client); await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <Client, ClientDto>(client)); }
private void AddClients() { var client42 = new Client(_guidGenerator.Create(), "42") { ProtocolType = "TestProtocol-42" }; client42.AddCorsOrigin("Origin1"); client42.AddScope("api1"); _clientRepository.Insert(client42); }
private async Task AddClients() { var client42 = new Client(_guidGenerator.Create(), "42") { ProtocolType = "TestProtocol-42" }; client42.AddCorsOrigin("Origin1"); client42.AddScope("Test-ApiScope-Name-1"); await _clientRepository.InsertAsync(client42); }
private async Task AddClients() { var client42 = new Client(_guidGenerator.Create(), "42") { ProtocolType = "TestProtocol-42" }; client42.AddCorsOrigin("Origin1"); client42.AddScope("api1"); await _clientRepository.InsertAsync(client42).ConfigureAwait(false); }
public async Task <IActionResult> CreateClient(string clientId) { var apiResource = await _apiResourceRepository.FindByNameAsync("api1"); if (apiResource == null) { apiResource = new ApiResource(GuidGenerator.Create(), "api1"); await _apiResourceRepository.InsertAsync(apiResource); } var client = new Client(GuidGenerator.Create(), clientId); client.AddGrantTypes(GrantTypes.ClientCredentials); client.AddSecret("secret".Sha256()); client.AddScope("api1"); await _clientRepository.InsertAsync(client); return(Content("OK: " + client.Id)); }
private async Task AddClients() { var client = new Client(_testData.Client1Id, "ClientId1") { Description = nameof(Client.Description), ClientName = nameof(Client.ClientName), ClientUri = nameof(Client.ClientUri), LogoUri = nameof(Client.LogoUri), ProtocolType = nameof(Client.ProtocolType), FrontChannelLogoutUri = nameof(Client.FrontChannelLogoutUri) }; client.AddCorsOrigin("https://client1-origin.com"); client.AddCorsOrigin("https://{0}.abp.io"); client.AddClaim(nameof(ClientClaim.Type), nameof(ClientClaim.Value)); client.AddGrantType(nameof(ClientGrantType.GrantType)); client.AddIdentityProviderRestriction(nameof(ClientIdPRestriction.Provider)); client.AddPostLogoutRedirectUri(nameof(ClientPostLogoutRedirectUri.PostLogoutRedirectUri)); client.AddProperty(nameof(ClientProperty.Key), nameof(ClientProperty.Value)); client.AddRedirectUri(nameof(ClientRedirectUri.RedirectUri)); client.AddScope(nameof(ClientScope.Scope)); client.AddSecret(nameof(ClientSecret.Value)); await _clientRepository.InsertAsync(client); await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId2")); await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId3")); var client42 = new Client(_guidGenerator.Create(), "42") { ProtocolType = "TestProtocol-42" }; client42.AddCorsOrigin("Origin1"); client42.AddScope("Test-ApiScope-Name-1"); await _clientRepository.InsertAsync(client42); }
public virtual async Task <ClientDto> CloneAsync(ClientCloneInputDto clientCloneInput) { var clientIdExists = await ClientRepository.CheckClientIdExistAsync(clientCloneInput.ClientId); if (clientIdExists) { throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ClientIdExisted, clientCloneInput.ClientId]); } var srcClient = await ClientRepository.GetAsync(clientCloneInput.SourceClientId); var client = new Client(GuidGenerator.Create(), clientCloneInput.ClientId); client.ClientName = clientCloneInput.ClientName; client.Description = clientCloneInput.Description; client.AbsoluteRefreshTokenLifetime = srcClient.AbsoluteRefreshTokenLifetime; client.AccessTokenLifetime = srcClient.AccessTokenLifetime; client.AccessTokenType = srcClient.AccessTokenType; client.AllowAccessTokensViaBrowser = srcClient.AllowAccessTokensViaBrowser; client.AllowOfflineAccess = srcClient.AllowOfflineAccess; client.AllowPlainTextPkce = srcClient.AllowPlainTextPkce; client.AllowRememberConsent = srcClient.AllowRememberConsent; client.AlwaysIncludeUserClaimsInIdToken = srcClient.AlwaysIncludeUserClaimsInIdToken; client.AlwaysSendClientClaims = srcClient.AlwaysSendClientClaims; client.AuthorizationCodeLifetime = srcClient.AuthorizationCodeLifetime; client.BackChannelLogoutSessionRequired = srcClient.BackChannelLogoutSessionRequired; client.BackChannelLogoutUri = srcClient.BackChannelLogoutUri; client.ClientClaimsPrefix = srcClient.ClientClaimsPrefix; client.ConsentLifetime = srcClient.ConsentLifetime; client.DeviceCodeLifetime = srcClient.DeviceCodeLifetime; client.Enabled = srcClient.Enabled; client.EnableLocalLogin = srcClient.EnableLocalLogin; client.FrontChannelLogoutSessionRequired = srcClient.FrontChannelLogoutSessionRequired; client.FrontChannelLogoutUri = srcClient.FrontChannelLogoutUri; client.IdentityTokenLifetime = srcClient.IdentityTokenLifetime; client.IncludeJwtId = srcClient.IncludeJwtId; client.LogoUri = srcClient.LogoUri; client.PairWiseSubjectSalt = srcClient.PairWiseSubjectSalt; client.ProtocolType = srcClient.ProtocolType; client.RefreshTokenExpiration = srcClient.RefreshTokenExpiration; client.RefreshTokenUsage = srcClient.RefreshTokenUsage; client.RequireClientSecret = srcClient.RequireClientSecret; client.RequireConsent = srcClient.RequireConsent; client.RequirePkce = srcClient.RequirePkce; client.SlidingRefreshTokenLifetime = srcClient.SlidingRefreshTokenLifetime; client.UpdateAccessTokenClaimsOnRefresh = srcClient.UpdateAccessTokenClaimsOnRefresh; client.UserCodeType = srcClient.UserCodeType; client.UserSsoLifetime = srcClient.UserSsoLifetime; if (clientCloneInput.CopyAllowedCorsOrigin) { foreach (var corsOrigin in srcClient.AllowedCorsOrigins) { client.AddCorsOrigin(corsOrigin.Origin); } } if (clientCloneInput.CopyAllowedGrantType) { foreach (var grantType in srcClient.AllowedGrantTypes) { client.AddGrantType(grantType.GrantType); } } if (clientCloneInput.CopyAllowedScope) { foreach (var scope in srcClient.AllowedScopes) { client.AddScope(scope.Scope); } } if (clientCloneInput.CopyClaim) { foreach (var claim in srcClient.Claims) { client.AddClaim(claim.Value, claim.Type); } } if (clientCloneInput.CopyIdentityProviderRestriction) { foreach (var provider in srcClient.IdentityProviderRestrictions) { client.AddIdentityProviderRestriction(provider.Provider); } } if (clientCloneInput.CopyPostLogoutRedirectUri) { foreach (var uri in srcClient.PostLogoutRedirectUris) { client.AddPostLogoutRedirectUri(uri.PostLogoutRedirectUri); } } if (clientCloneInput.CopyPropertie) { foreach (var property in srcClient.Properties) { client.AddProperty(property.Key, property.Value); } } if (clientCloneInput.CopyRedirectUri) { foreach (var uri in srcClient.RedirectUris) { client.AddRedirectUri(uri.RedirectUri); } } client = await ClientRepository.InsertAsync(client); return(ObjectMapper.Map <Client, ClientDto>(client)); }
private async Task <Client> CreateClientAsync( string name, IEnumerable <string> scopes, IEnumerable <string> grantTypes, string secret = null, string redirectUri = null, string postLogoutRedirectUri = null, string frontChannelLogoutUri = null, bool requireClientSecret = true, bool requirePkce = false, IEnumerable <string> permissions = null, IEnumerable <string> corsOrigins = null) { Client client = await _clientRepository.FindByClientIdAsync(name); if (client == null) { client = await _clientRepository.InsertAsync( new Client( _guidGenerator.Create(), name ) { ClientName = name, ProtocolType = "oidc", Description = name, AlwaysIncludeUserClaimsInIdToken = true, AllowOfflineAccess = true, AbsoluteRefreshTokenLifetime = 31536000, //365 days AccessTokenLifetime = 31536000, //365 days AuthorizationCodeLifetime = 300, IdentityTokenLifetime = 300, RequireConsent = false, FrontChannelLogoutUri = frontChannelLogoutUri, RequireClientSecret = requireClientSecret, RequirePkce = requirePkce }, autoSave : true ); } foreach (string scope in scopes) { if (client.FindScope(scope) == null) { client.AddScope(scope); } } foreach (string grantType in grantTypes) { if (client.FindGrantType(grantType) == null) { client.AddGrantType(grantType); } } if (!secret.IsNullOrEmpty()) { if (client.FindSecret(secret) == null) { client.AddSecret(secret); } } if (redirectUri != null) { if (client.FindRedirectUri(redirectUri) == null) { client.AddRedirectUri(redirectUri); } } if (postLogoutRedirectUri != null) { if (client.FindPostLogoutRedirectUri(postLogoutRedirectUri) == null) { client.AddPostLogoutRedirectUri(postLogoutRedirectUri); } } if (permissions != null) { await _permissionDataSeeder.SeedAsync( ClientPermissionValueProvider.ProviderName, name, permissions, null ); } if (corsOrigins != null) { foreach (string origin in corsOrigins) { if (!origin.IsNullOrWhiteSpace() && client.FindCorsOrigin(origin) == null) { client.AddCorsOrigin(origin); } } } return(await _clientRepository.UpdateAsync(client)); }