public void GenerateNewClientId() { var secret = ClientIdGenerator.Generate(64); ClientSecrets = new List <ClientSecret> { new ClientSecret(IModels.HashExtensions.Sha256(secret), secret) }; }
public static async Task <Client> CreateNewEntry( IClientRepository repository, string clientName, int clientTypeId ) { if (string.IsNullOrWhiteSpace(clientName)) { throw new ArgumentException("The ClientName must be specified", nameof(clientName)); } if (!await repository.HasUniqName(clientName)) { throw new ArgumentException("An other tenant has the same name.", nameof(clientName)); } var client = new Client { Id = Guid.NewGuid(), ClientName = clientName, ClientTypeId = clientTypeId, ClientId = ClientIdGenerator.Generate(32), AllowedScopes = new List <string> { IdentityServerConstants.StandardScopes.OpenId } }; if (clientTypeId == ClientType.SinglePage.Id) { client.RequireConsent = false; client.AllowedGrantTypes = IModels.GrantTypes.Implicit.ToList(); client.AccessTokenType = (int)IModels.AccessTokenType.Jwt; client.AllowAccessTokensViaBrowser = true; client.AlwaysIncludeUserClaimsInIdToken = true; } else if (clientTypeId == ClientType.MachineToMachine.Id) { client.RequireConsent = false; client.AllowedGrantTypes = IModels.GrantTypes.ClientCredentials.ToList(); client.ClientSecrets = new List <ClientSecret> { new ClientSecret(IModels.HashExtensions.Sha256("secret")) }; client.RequireClientSecret = true; } return(client); }