Example #1
0
        public async Task <RefreshTokenIdentityAdto> CreateRefreshTokenAsync(CreateRefreshTokenAdto createRefreshTokenAdto)
        {
            using (ITransaction transaction = _transactionManager.Create())
            {
                try
                {
                    Identity identity = await _identityCommandRepository.GetByIdAsync(createRefreshTokenAdto.IdentityId);

                    if (identity == null)
                    {
                        throw new BusinessApplicationException(ExceptionType.NotFound, "Identity not found");
                    }

                    AuthenticationGrantTypeRefreshToken authenticationGrantTypeRefreshToken = (AuthenticationGrantTypeRefreshToken)await
                                                                                              _authenticationServiceCommandRepository.GetSingleAsync(a => a is AuthenticationGrantTypeRefreshToken);

                    if (authenticationGrantTypeRefreshToken == null)
                    {
                        throw new BusinessApplicationException(ExceptionType.NotFound, "Refresh tokens are not configured");
                    }

                    RefreshTokenIdentityDdto refreshTokenIdentityDdto = await _createRefreshTokenCommand.ExecuteAsync(identity, authenticationGrantTypeRefreshToken);

                    await _identityCommandRepository.UpdateAsync(identity);

                    transaction.Commit();

                    return(new RefreshTokenIdentityAdto
                    {
                        Token = refreshTokenIdentityDdto.Token
                    });
                }
                catch (DomainValidationRuleException e)
                {
                    throw new BusinessValidationRuleApplicationException(e.ValidationResult);
                }
            }
        }
 public Task <RefreshTokenIdentityAdto> CreateRefreshTokenAsync(CreateRefreshTokenAdto createRefreshTokenAdto)
 {
     return(_securityApplicationService.SecureAsync(() => _identityApplicationService.CreateRefreshTokenAsync(createRefreshTokenAdto),
                                                    IdentityAuthorisationContext.Create(createRefreshTokenAdto.IdentityId, AuthorisationAction.Update)));
 }