public RegistrationResultReceived(string id, string processId, ClientRegistrationResponse parameter, int order) { Id = id; ProcessId = processId; Parameter = parameter; Order = order; }
public ClientRegistrationResponse ClientRegistration(ClientRegistrationRequest req) { if (_context.Clients.Where(p => p.Login.Equals(req.Login)) .FirstOrDefault() != null) { throw new LoginException($"Client with login={req.Login} has already exists"); } var hashed = BCrypt.Net.BCrypt.HashPassword(req.Password, 13); Client client = new Client { FirstName = req.FirstName, LastName = req.LastName, Email = req.Email, Phone = req.Phone, Login = req.Login, Password = hashed }; _context.Clients.Add(client); _context.SaveChanges(); ClientRegistrationResponse resp = new ClientRegistrationResponse { FirstName = client.FirstName, LastName = client.LastName, Email = client.Email, Phone = client.Phone, Login = client.Login }; return(resp); }
public string GetPayload(ClientRegistrationResponse parameter) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } var result = new Payload { ClientId = parameter.ClientId, Content = parameter }; return(JsonConvert.SerializeObject(result)); }
internal static async Task Main(string[] args) { InitializeGrpc(); string clientName = RetrieveClientName(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); var retrieveMessageTask = RetrieveMessagesAsync(cancellationTokenSource.Token); ClientRegistrationResponse response = ClientRegistry.Register(new ClientRegistrationRequest { Name = clientName }); var me = new Interface.Client { Id = response.Id, Name = clientName }; do { var message = Console.ReadLine(); if (!string.IsNullOrEmpty(message)) { await ChatStream.RequestStream.WriteAsync(new ChatMessage(new ChatMessage { From = me, Message = message })); } else if (message != null && message.Equals("quit", StringComparison.InvariantCultureIgnoreCase)) { break; } } while (true); cancellationTokenSource.Cancel(); await retrieveMessageTask; }
public async Task <ClientRegistrationResponse> Execute(RegistrationParameter registrationParameter) { if (registrationParameter == null) { throw new ArgumentNullException(nameof(registrationParameter)); } _simpleIdentityServerEventSource.StartRegistration(registrationParameter.ClientName); var client = _generateClientFromRegistrationRequest.Execute(registrationParameter); client.AllowedScopes = new List <Scope> { Constants.StandardScopes.OpenId, Constants.StandardScopes.ProfileScope, Constants.StandardScopes.Address, Constants.StandardScopes.Email, Constants.StandardScopes.Phone }; var clientId = Guid.NewGuid().ToString(); if (string.IsNullOrWhiteSpace(client.ClientName)) { client.ClientName = "Unknown " + clientId; } var result = new ClientRegistrationResponse { ClientId = clientId, ClientSecretExpiresAt = 0, ClientIdIssuedAt = DateTime.UtcNow.ConvertToUnixTimestamp().ToString(CultureInfo.InvariantCulture), ApplicationType = Enum.GetName(typeof(ApplicationTypes), client.ApplicationType), ClientUri = GetDefaultValue(client.ClientUri), ClientName = GetDefaultValue(client.ClientName), Contacts = GetDefaultValues(client.Contacts).ToArray(), DefaultAcrValues = GetDefaultValue(client.DefaultAcrValues), GrantTypes = client.GrantTypes == null ? new string[0] : client.GrantTypes.Select(g => Enum.GetName(typeof(GrantType), g)).ToArray(), DefaultMaxAge = client.DefaultMaxAge, IdTokenEncryptedResponseAlg = GetDefaultValue(client.IdTokenEncryptedResponseAlg), IdTokenEncryptedResponseEnc = GetDefaultValue(client.IdTokenEncryptedResponseEnc), JwksUri = GetDefaultValue(client.JwksUri), RequestObjectEncryptionAlg = GetDefaultValue(client.RequestObjectEncryptionAlg), RequestObjectEncryptionEnc = GetDefaultValue(client.RequestObjectEncryptionEnc), IdTokenSignedResponseAlg = GetDefaultValue(client.IdTokenSignedResponseAlg), LogoUri = GetDefaultValue(client.LogoUri), Jwks = registrationParameter.Jwks, RequireAuthTime = client.RequireAuthTime, InitiateLoginUri = GetDefaultValue(client.InitiateLoginUri), PolicyUri = GetDefaultValue(client.PolicyUri), RequestObjectSigningAlg = GetDefaultValue(client.RequestObjectSigningAlg), UserInfoEncryptedResponseAlg = GetDefaultValue(client.UserInfoEncryptedResponseAlg), UserInfoEncryptedResponseEnc = GetDefaultValue(client.UserInfoEncryptedResponseEnc), UserInfoSignedResponseAlg = GetDefaultValue(client.UserInfoSignedResponseAlg), TosUri = GetDefaultValue(client.TosUri), SectorIdentifierUri = GetDefaultValue(client.SectorIdentifierUri), SubjectType = GetDefaultValue(client.SubjectType), ResponseTypes = client.ResponseTypes == null ? new string[0] : client.ResponseTypes.Select(r => Enum.GetName(typeof(ResponseType), r)).ToArray(), RequestUris = GetDefaultValues(client.RequestUris).ToList(), RedirectUris = GetDefaultValues(client.RedirectionUrls).ToArray(), TokenEndpointAuthSigningAlg = GetDefaultValue(client.TokenEndPointAuthSigningAlg), TokenEndpointAuthMethod = Enum.GetName(typeof(TokenEndPointAuthenticationMethods), client.TokenEndPointAuthMethod), ScimProfile = client.ScimProfile }; if (client.TokenEndPointAuthMethod != TokenEndPointAuthenticationMethods.private_key_jwt) { result.ClientSecret = Guid.NewGuid().ToString(); client.Secrets = new List <ClientSecret> { new ClientSecret { Type = ClientSecretTypes.SharedSecret, Value = _encryptedPasswordFactory.Encrypt(result.ClientSecret) } }; } client.ClientId = result.ClientId; await _clientRepository.InsertAsync(client); _simpleIdentityServerEventSource.EndRegistration(result.ClientId, client.ClientName); return(result); }
public ClientRegistrationResponse Post([FromBody] ClientRegistrationRequest request) { try { _logger.Info("register new client: "); _logger.Info(JsonConvert.SerializeObject(request, Formatting.Indented)); var loginName = $"{request.FirstName[0].ToString().ToLowerInvariant()}.{request.LastName.ToLowerInvariant()}"; var clientId = _userService.CreateClient(new RegisteredClient { Country = request.Country, State = RegisteredClientState.Pending, CreationUser = loginName, CreationDate = DateTime.Now, }); var workContext = new WorkContext { UserId = Guid.Empty, LoginName = loginName }; var user = _userService.CreateUser(workContext, new User { RegisteredClientId = clientId, LoginName = loginName, FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, EmailIsValidated = false, Password = request.EncryptedPassword, PasswordLastChangedDate = DateTime.Now, IsActive = true, }); var mailServerConfig = new MailServerConfiguration { Hostname = "smtp.gmail.com", Port = 587, Username = "******", Password = "******", From = "*****@*****.**", EnableSsl = true, IsActive = true }; var renderedMessage = _mailService.RenderMailContent("0000000000", "AppSolutions", "NewClientRegistrationUserMailAddressValidation", "EN", new { FirstName = request.FirstName, LastName = request.LastName, MailAddress = request.Email, VerificationLink = $"http://localhost:29328/User/EmailVerification/{clientId}/{user.UserId}" }); var message = new MailMessage { From = new MailAddress { Address = mailServerConfig.From }, To = new List <MailAddress> { new MailAddress { Address = request.Email } }, IsBodyHtml = renderedMessage.IsBodyHtml, Subject = renderedMessage.Subject, Body = renderedMessage.Body, }; _mailService.SendMail(mailServerConfig, message); return(ClientRegistrationResponse.Success(clientId, request.Email)); } catch (Exception e) { _logger.Error(e); return(ClientRegistrationResponse.Error(e)); } }