public async Task <JwtWithRefreshToken> Refresh(string token, string refreshToken) { IJWTService jwtService = SecurityServiceFactory.GetService(typeof(IJWTService)) as IJWTService; IIdentityUserService identityUserService = SecurityServiceFactory.GetService(typeof(IIdentityUserService)) as IIdentityUserService; var principal = jwtService.GetPrincipalFromExpiredToken(token); var username = principal.Identity.Name; var identityUserId = principal.Claims.Single(x => x.Type == "nameidentifier").Value; var applicationUser = await identityUserService.GetApplicationUserAsync(identityUserId); var savedRefreshToken = GetRefreshToken(identityUserId); //retrieve the refresh token from a data store if (savedRefreshToken != refreshToken) { throw new SecurityTokenException("Invalid refresh token"); } var newJwtToken = jwtService.GenerateJwtToken(applicationUser); var newRefreshToken = GenerateRefreshToken(); DeleteRefreshToken(username, refreshToken); SaveRefreshToken(username, newRefreshToken); return(new JwtWithRefreshToken { AccessToken = newJwtToken.AccessToken, Expires = newJwtToken.Expires, Issued = newJwtToken.Issued, RefreshToken = newRefreshToken, }); }
public CustomerService( ICustomerRepository repository, IIdentityUserService identityUserService, ICompanyService companyService) : base(repository, identityUserService, companyService) { }
public void SetUp() { _identityUserServiceMock = MockRepository.GenerateMock <IIdentityUserService>(); _identityRoleServiceMock = MockRepository.GenerateMock <IIdentityRoleService>(); _userStore = new UserStore <IdentityUser>(); }
//private Task<IdentityResult> _createUserAsync; public IdentityController(IIdentityUserService identityUserService, IIdentityRoleService identityRoleService, IIdentityUserRoleService identityUserRoleService) { _identityUserService = identityUserService; _identityRoleService = identityRoleService; _identityUserRoleService = identityUserRoleService; }
public EmployeeService( IEmployeeRepository <T> repository, IIdentityUserService identityUserService, ICompanyService companyService) : base(repository, identityUserService) { CompanyService = companyService; }
public UserContactListController(IUnitOfWorkPseezEnt uow, IIdentityUserService identityUserService, IUserContactListService userContactListService, IContactListService contactListService) { _uow = uow; _identityUserService = identityUserService; _userContactListService = userContactListService; _contactListService = contactListService; }
public static void Class_Initialize(TestContext testContext) { dbContextOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "LinkTestDb") .Options; var linkRepository = new Repository <Link>(new ApplicationDbContext(dbContextOptions)); userService = new TestIdentityUserService(new ApplicationDbContext(dbContextOptions)); linkService = new LinkService(linkRepository, userService); }
public AccountController( IIdentityServerInteractionService interaction, IClientStore clientStore, IAuthenticationSchemeProvider schemeProvider, IEventService events, IIdentityUserService identityUserService) { this.identityUserService = identityUserService; this.interaction = interaction; this.clientStore = clientStore; this.schemeProvider = schemeProvider; this.events = events; }
public IdentityAccountService( UserManager <AppUser> userManager, IIdentityUserService identityUserService, IIdentityRoleService identityRoleService, IConfiguration configuration, IEncryptionService encryptionService) { _userManager = userManager; _identityUserService = identityUserService; _identityRoleService = identityRoleService; _configuration = configuration; _encryptionService = encryptionService; }
public ExternalController( IIdentityServerInteractionService interaction, IClientStore clientStore, IEventService events, ILogger <ExternalController> logger, Config config, IIdentityUserService identityUserService) { this.identityUserService = identityUserService; this.interaction = interaction; this.clientStore = clientStore; this.logger = logger; this.events = events; this.config = config; }
public async Task <Jwt> Login(LoginModel model, Func <string, string, string> generateConfirmationLink, string PathToEmailFile) { try { Jwt jwt = null; IJWTService jwtService = SecurityServiceFactory.GetService(typeof(IJWTService)) as IJWTService; IIdentityUserService identityService = SecurityServiceFactory.GetService(typeof(IIdentityUserService)) as IIdentityUserService; ApplicationUser user = await UserManager.FindByEmailAsync(model.Email); if (user == null) { throw new InvalidOperationException("Incorrect email or password"); } bool isPasswordCorrect = await UserManager.CheckPasswordAsync(user, model.Password); if (!isPasswordCorrect) { throw new InvalidOperationException("Incorrect email or password"); } var isEmailConfirmed = await UserManager.IsEmailConfirmedAsync(user); if (!isEmailConfirmed) { await identityService.ResendEmailConfirmationAsync(user.Email, generateConfirmationLink, PathToEmailFile); throw new InvalidOperationException($"{user.Email} Has Not Been Confirmed. Please Retry Email Confirmation"); } if (model.RememberMe) { jwt = await jwtService.GenerateJWtWithRefreshTokenAsync(user); } else { jwt = jwtService.GenerateJwtToken(user); } return(jwt); } catch (Exception ex) { throw ex; } }
public async Task <JwtWithRefreshToken> GenerateJWtWithRefreshTokenAsync(ApplicationUser user) { IRefreshTokenService refreshTokenService = SecurityServiceFactory.GetService(typeof(IRefreshTokenService)) as IRefreshTokenService; IIdentityUserService identityUserService = SecurityServiceFactory.GetService(typeof(IIdentityUserService)) as IIdentityUserService; //var applicationUser = await identityUserService.GetApplicationUserAsync(identityUserId); var jwtToken = GenerateJwtToken(user); var refreshToken = refreshTokenService.GenerateAndSaveRefreshToken(user.Id); return(new JwtWithRefreshToken { AccessToken = jwtToken.AccessToken, Expires = jwtToken.Expires, Issued = jwtToken.Issued, RefreshToken = refreshToken, }); }
public CreateUserCommandHandlerTests() { _mapper = Mock.Of <IMapper>(); _createUserCommand = new CreateUserCommand { Email = "*****@*****.**" }; _requestResponse = new RequestResponse { Successful = true }; var mockService = new Mock <IIdentityUserService>(); mockService.Setup(s => s.CreateUserAsync(It.IsAny <CreateUserCommand>())).Returns(Task.FromResult(_requestResponse)).Verifiable(); _identityUserService = mockService.Object; _createUserCommandHandler = new CreateUserCommandHandler(_identityUserService); _createUserCommand = new CreateUserCommand(); Mock.Get(_mapper).Setup(m => m.Map <AppUser>(_createUserCommand)).Returns(_appUser); }
public LoggerService(IIdentityUserService identityUserService, IConfiguration configuration) { _identityUserService = identityUserService; _databaseId = configuration.GetValue <string>("CosmosDb:DatabaseId"); //TODO: refactor magic strings _infoContainerId = configuration.GetValue <string>("CosmosDb:InfoContaier"); _exceptionContainerId = configuration.GetValue <string>("CosmosDb:ExceptionsContainer"); cosmosClient = new CosmosClient( configuration.GetValue <string>("CosmosDb:EndpointUri"), configuration.GetValue <string>("CosmosDb:PrimaryKey"), new CosmosClientOptions() { ApplicationName = "Esfer" }); Task.Run(async() => { _database = await cosmosClient.CreateDatabaseIfNotExistsAsync(_databaseId); _infoContainer = await _database.CreateContainerIfNotExistsAsync(_infoContainerId, "/UserId", 400); _exceptionContainer = await _database.CreateContainerIfNotExistsAsync(_exceptionContainerId, "/UserId", 400); }).Wait(); }
public GenerateRecoveryCodesModel(IIdentityUserService userService, ILogger <GenerateRecoveryCodesModel> logger) { this.userService = userService ?? throw new ArgumentNullException(nameof(userService)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public CreateUserCommandHandler(IIdentityUserService identityUserService) { _identityUserService = identityUserService; }
public GetUsersWithPaginationQueryHandler(IIdentityUserService identityUserService) { _identityUserService = identityUserService; }
public PersonalDataModel(IIdentityUserService userService) => this.userService = userService ?? throw new ArgumentNullException(nameof(userService));
public UserController(IIdentityUserService service) { _service = service; }
public DeletePersonalDataModel(ILogger <DeletePersonalDataModel> logger, IIdentityUserService userService) { this.userService = userService ?? throw new ArgumentNullException(nameof(userService)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public GetUsersQueryHandler(IIdentityUserService identityUserService) { _identityUserService = identityUserService; }
public ChangeUserToTicketCommandHandler(IApplicationDbContext dbContex, IIdentityUserService identityUserService) { _dbContex = dbContex; _identityUserService = identityUserService; }
public ForgotPasswordModel(IIdentityUserService userService, IEmailSender emailSender) { this.userService = userService ?? throw new ArgumentNullException(nameof(userService)); this.emailSender = emailSender ?? throw new ArgumentNullException(nameof(emailSender)); }
public AssignUserToRoleCommandHandler(IIdentityRoleService identityRoleService, IIdentityUserService identityUserService) { _identityRoleService = identityRoleService; _identityUserService = identityUserService; }
public LogoutModel(IIdentityUserService userService, ILogger <LogoutModel> logger) { this.userService = userService ?? throw new ArgumentNullException(nameof(userService)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public IdentityUserClient(EndpointConfiguration endpoint) { channel = new ChannelFactory <IIdentityUserService>(GetBindingForEndpoint(EndpointConfigurationType.NetTcpBinding), GetEndpointAddress(endpoint)).CreateChannel(); }
public LoginWithRecoveryCodeModel(ILogger <LoginWithRecoveryCodeModel> logger, IIdentityUserService userService) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.userService = userService ?? throw new ArgumentNullException(nameof(userService)); }
public AssignUserToTicketCommandHandler(IApplicationDbContext dbContext, IIdentityUserService identityUserService) { _dbContext = dbContext; _identityUserService = identityUserService; }
public ProfileService(IIdentityUserService userService) { this.userService = userService; }
public UsersController(IIdentityUserService identityUserService) { _identityUserService = identityUserService; }