/// <inheritdoc/> public async Task RequestTokenWithExternalProviderAsync(ExternalLoginRequest externalLoginRequest) { if (!this.IsAuthenticated) { this.authenticationResult = await this.authenticationServiceAgent.RequestTokenWithExternalProviderAsync(externalLoginRequest); await this.LoadUserTokensAsync(); } }
/// <inheritdoc/> public async Task RequestTokenAsync(LoginRequest loginRequest) { if (!this.IsAuthenticated) { this.authenticationResult = await this.authenticationServiceAgent.RequestTokenAsync(loginRequest); await this.LoadUserTokensAsync(); } }
/// <inheritdoc/> public async Task <BearerAuthenticationResult> BuildJwtTokenForUserAsync(Guid userId) { try { var user = await this.userManager.FindByIdAsync(userId.ToString()); var userClaims = await this.userClaimsService.GetUserClaimsForJwtTokenAsync(userId); string jwt = this.BuildJwtToken(userClaims); string refreshToken = this.context.BuildRefreshToken(user); await this.context.SaveChangesAsync(); return(BearerAuthenticationResult.SuccessResult(jwt, refreshToken)); } catch (Exception ex) { await this.logger.LogErrorAsync(ex); return(null); } }
/// <inheritdoc/> public async Task <BearerAuthenticationResult> RefreshJwtTokenAsync(Guid?userId, string refreshToken) { User user = null; if (userId.HasValue) { user = await this.userManager.FindByIdAsync(userId.ToString()); } else { user = await this.context.Set <User>().AsQueryable().FirstOrDefaultAsync(x => x.RefreshToken == refreshToken); } if (user != null && user.RefreshToken == refreshToken && user.RefreshTokenExpiration.HasValue && user.RefreshTokenExpiration > DateTime.Now) { var userClaims = await this.userClaimsService.GetUserClaimsForJwtTokenAsync(user.Id); string jwt = this.BuildJwtToken(userClaims); return(BearerAuthenticationResult.SuccessResult(jwt, refreshToken)); } return(BearerAuthenticationResult.FailedResult); }