public void GenerateNewClientId() { var secret = ClientIdGenerator.Generate(64); ClientSecrets = new List <ClientSecret> { new ClientSecret(IModels.HashExtensions.Sha256(secret), secret) }; }
public string RegisterUser(string name, string role, string emailaddress) { var clientIdGenerator = new ClientIdGenerator(); var clientSecretGenerator = new ClientSecretGenerator(); var repository = new ClientRepository.ClientRepository(); var connectionString = ConfigurationManager.ConnectionStrings["OAuthWCF.IdSrv"].ConnectionString; var options = new EntityFrameworkServiceOptions { ConnectionString = connectionString }; IClientConfigurationDbContext clientdb = new ClientConfigurationDbContext { Database = { Connection = { ConnectionString = connectionString } } }; var clients = new[] { new Client { ClientId = clientIdGenerator.GenerateClientIdAsync(clientdb), ClientSecrets = new List <Secret> { clientSecretGenerator.GenerateSecret(clientdb) }, ClientName = name, Flow = Flows.ClientCredentials, AllowedScopes = new List <string> { role }, Enabled = true, Claims = new List <Claim>() { new Claim(ClaimTypes.Name, name), new Claim(ClaimTypes.Role, role), new Claim(ClaimTypes.Email, emailaddress) }, AllowClientCredentialsOnly = true } }; repository.Add(clients, options); return(string.Join(".", clients.First().ClientId, clients.First().ClientSecrets.First())); }
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); }
public void Initialize() { // initialize communication system ClientProxyBase.SourceId = ClientIdGenerator.GenerateId(ClientTypeEnum.External); ClientProxyBase.ConfigureClientProxyForCallback(new ConfigurationForCallback("TcpEndpointForCallbackMode")); ClientProxyBase.Faulted += ClientProxyBase_Faulted; try { ClientProxyBase.Open(); } catch (Exception ex) { LOGGER.Error(string.Format("Failed to open connection. Reason: {0}", ex.Message)); mFaultHandlerEvent.Set(); } mFaultHandlerThread = new Thread(new ThreadStart(FaultHandlerThreadMain)); mFaultHandlerThread.Name = "FaultHandlerThread"; mFaultHandlerThread.Start(); }
public void Initialize() { // create wcf binding and endpoint address ClientProxyBase.SourceId = ClientIdGenerator.GenerateId(ClientTypeEnum.External); NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); binding.Name = "TcpEndpoint"; binding.OpenTimeout = TimeSpan.FromMinutes(1); binding.CloseTimeout = TimeSpan.FromMinutes(1); binding.ReceiveTimeout = TimeSpan.FromMinutes(10); binding.SendTimeout = TimeSpan.FromMinutes(10); binding.MaxBufferSize = 2147483647; binding.MaxReceivedMessageSize = 2147483647; binding.TransferMode = TransferMode.Buffered; binding.ReaderQuotas.MaxDepth = 2147483647; binding.ReaderQuotas.MaxStringContentLength = 2147483647; binding.ReaderQuotas.MaxArrayLength = 2147483647; binding.ReaderQuotas.MaxBytesPerRead = 2147483647; binding.ReaderQuotas.MaxNameTableCharCount = 2147483647; binding.Security.Mode = SecurityMode.None; binding.Security.Message.ClientCredentialType = MessageCredentialType.None; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; EndpointAddress endpoint = new EndpointAddress(ConfigurationManager.AppSettings["SesameServiceUrl"]); // initialize communication system ClientProxyBase.ConfigureClientProxyForCallback(new ConfigurationForCallback(binding, endpoint)); ClientProxyBase.Faulted += ClientProxyBase_Faulted; try { ClientProxyBase.Open(); } catch (Exception ex) { LOGGER.Error(string.Format("Failed to open connection. Reason: {0}", ex.Message)); mFaultHandlerEvent.Set(); } mFaultHandlerThread = new Thread(new ThreadStart(FaultHandlerThreadMain)); mFaultHandlerThread.Name = "FaultHandlerThread"; mFaultHandlerThread.Start(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ClientProxyBase.SourceId = ClientIdGenerator.GenerateId(ClientTypeEnum.External); ClientProxyBase.ConfigureClientProxyForCallback(new ConfigurationForCallback("TcpEndpointForCallbackMode")); ClientProxyBase.Faulted += ClientProxyBase_Faulted; try { ClientProxyBase.Open(); } catch (Exception ex) { LOGGER.Error(string.Format("Failed to open connection. Reason: {0}", ex.Message)); mFaultHandlerEvent.Set(); } mFaultHandlerThread = new Thread(new ThreadStart(FaultHandlerThreadMain)); mFaultHandlerThread.Name = "FaultHandlerThread"; mFaultHandlerThread.Start(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, IWebHostEnvironment env, ILoggerFactory loggerFactory, IConfiguration config) { // initialize logger loggerFactory.AddLog4Net(); Forge.Logging.LogManager.LOGGER = Forge.Logging.Log4net.Log4NetManager.Instance; Forge.Logging.LogUtils.LogAll(); LOGGER = LogManager.GetLogger(typeof(Startup)); // bind configuration to POCO SesameConfiguration.Instance = config.GetSection("SesameConfiguration").Get <SesameConfiguration>(); // create wcf binding and endpoint address ClientProxyBase.SourceId = ClientIdGenerator.GenerateId(ClientTypeEnum.External); NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); binding.Name = "TcpEndpoint"; binding.OpenTimeout = TimeSpan.FromMinutes(1); binding.CloseTimeout = TimeSpan.FromMinutes(1); binding.ReceiveTimeout = TimeSpan.FromMinutes(10); binding.SendTimeout = TimeSpan.FromMinutes(10); binding.MaxBufferSize = 2147483647; binding.MaxReceivedMessageSize = 2147483647; binding.TransferMode = TransferMode.Buffered; binding.ReaderQuotas.MaxDepth = 2147483647; binding.ReaderQuotas.MaxStringContentLength = 2147483647; binding.ReaderQuotas.MaxArrayLength = 2147483647; binding.ReaderQuotas.MaxBytesPerRead = 2147483647; binding.ReaderQuotas.MaxNameTableCharCount = 2147483647; binding.Security.Mode = SecurityMode.None; binding.Security.Message.ClientCredentialType = MessageCredentialType.None; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; EndpointAddress endpoint = new EndpointAddress(SesameConfiguration.Instance.SesameServiceUrl); // initialize communication system ClientProxyBase.ConfigureClientProxyForCallback(new ConfigurationForCallback(binding, endpoint)); ClientProxyBase.Faulted += ClientProxyBase_Faulted; try { ClientProxyBase.Open(); } catch (Exception ex) { LOGGER.Error(string.Format("Failed to open connection. Reason: {0}", ex.Message)); mFaultHandlerEvent.Set(); } mFaultHandlerThread = new Thread(new ThreadStart(FaultHandlerThreadMain)); mFaultHandlerThread.Name = "FaultHandlerThread"; mFaultHandlerThread.Start(); // register shutdown applicationLifetime.ApplicationStopping.Register(OnShutdown); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); }
public ClientIdGeneratorTests() { generator = new ClientIdGenerator(); }