コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 /// <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);
         }
     }
 }
コード例 #6
0
 /// <summary>
 /// Generates the identity.
 /// </summary>
 /// <returns>The generated identity instance.</returns>
 public object Generate()
 {
     return(generator.Generate());
 }