public string Create(User executor) { Guid id = _identityGenerator.Generate(); DateTime now = _timeProvider.Now(); DateTime expirationDateTime = _tokenExpirationProvider.GetExpiration(now); var tokenHandler = new JwtSecurityTokenHandler(); byte[] symmetricKey = _keyProvider.GetKey(); List <Claim> claims = executor.UserRoles.Select(x => new Claim(ClaimTypes.Role, x.Description)).ToList(); claims.Add(new Claim(ClaimTypes.Name, executor.Name)); claims.Add(new Claim("userguid", executor.Id.ToString())); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims), TokenIssuerName = "self", AppliesToAddress = "http://www.example.com", Lifetime = new Lifetime(now, expirationDateTime), SigningCredentials = new SigningCredentials( new InMemorySymmetricSecurityKey(symmetricKey), "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256", "http://www.w3.org/2001/04/xmlenc#sha256"), }; SecurityToken token = tokenHandler.CreateToken(tokenDescriptor); string tokenString = tokenHandler.WriteToken(token); return(tokenString); }
public void Handle(IUserSession userIssuingCommand, CreatePasswordResetToken command) { var user = _readOnlyRepository.First <UserEmailLogin>(x => x.Email == command.Email); Guid tokenId = _idGenerator.Generate(); _writeableRepository.Create(new PasswordResetAuthorization(tokenId, user.Id, _timeProvider.Now())); NotifyObservers(new PasswordResetTokenCreated(tokenId, user.Id)); }
public async Task Handle(IUserSession userIssuingCommand, StartPasswordResetProcess command) { UserEmailLogin user = await _readOnlyRepository.First <UserEmailLogin>(x => x.Email == command.Email); Guid tokenId = _idGenerator.Generate(); await _tokenRepo.Create(new PasswordResetToken(tokenId, user.Id, _timeProvider.Now())); NotifyObservers(new PasswordResetTokenCreated(tokenId, user.Id)); }
public UserLoginSession Create(User executor) { DateTime dateTime = _tokenExpirationProvider.GetExpiration(_timeProvider.Now()); Guid token = _identityGenerator.Generate(); var userSession = new UserLoginSession(token, executor, dateTime); _writeableRepository.Create(userSession); return(userSession); }
/// <inheritdoc /> public void PersistEntries(IEnumerable <TEntry> entries) { foreach (var entry in entries) { if (entry is BaseEntry baseEntry) { baseEntry.SetId(_identityGenerator.Generate().ToString()); _entries.Add(entry); } } }
/// <summary> /// Generates the identity. /// </summary> /// <returns>The generated identity instance.</returns> public object Generate() { return(generator.Generate()); }