Merge pull request #820 from erikpique/feature/118
Token lifetime handling #118
This commit is contained in:
commit
01f6feb84d
@ -79,9 +79,16 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var user = await _loginService.FindByUsername(model.Email);
|
||||
|
||||
if (await _loginService.ValidateCredentials(user, model.Password))
|
||||
{
|
||||
AuthenticationProperties props = null;
|
||||
var props = new AuthenticationProperties
|
||||
{
|
||||
ExpiresUtc = DateTimeOffset.UtcNow.AddHours(2),
|
||||
AllowRefresh = true,
|
||||
RedirectUri = model.ReturnUrl
|
||||
};
|
||||
|
||||
if (model.RememberMe)
|
||||
{
|
||||
props = new AuthenticationProperties
|
||||
@ -91,7 +98,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Controllers
|
||||
};
|
||||
};
|
||||
|
||||
await _loginService.SignIn(user);
|
||||
await _loginService.SignInAsync(user, props);
|
||||
|
||||
// make sure the returnUrl is still valid, and if yes - redirect back to authorize endpoint
|
||||
if (_interaction.IsValidReturnUrl(model.ReturnUrl))
|
||||
|
@ -1,15 +1,17 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.eShopOnContainers.Services.Identity.API.Models;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Identity.API.Services
|
||||
{
|
||||
public class EFLoginService : ILoginService<ApplicationUser>
|
||||
{
|
||||
UserManager<ApplicationUser> _userManager;
|
||||
SignInManager<ApplicationUser> _signInManager;
|
||||
private UserManager<ApplicationUser> _userManager;
|
||||
private SignInManager<ApplicationUser> _signInManager;
|
||||
|
||||
public EFLoginService(UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager) {
|
||||
public EFLoginService(UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_signInManager = signInManager;
|
||||
}
|
||||
@ -24,8 +26,14 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Services
|
||||
return await _userManager.CheckPasswordAsync(user, password);
|
||||
}
|
||||
|
||||
public Task SignIn(ApplicationUser user) {
|
||||
public Task SignIn(ApplicationUser user)
|
||||
{
|
||||
return _signInManager.SignInAsync(user, true);
|
||||
}
|
||||
|
||||
public Task SignInAsync(ApplicationUser user, AuthenticationProperties properties, string authenticationMethod = null)
|
||||
{
|
||||
return _signInManager.SignInAsync(user, properties, authenticationMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Identity.API.Services
|
||||
{
|
||||
public interface ILoginService<T>
|
||||
{
|
||||
Task<bool> ValidateCredentials(T user, string password);
|
||||
|
||||
Task<T> FindByUsername(string user);
|
||||
|
||||
Task SignIn(T user);
|
||||
|
||||
Task SignInAsync(T user, AuthenticationProperties properties, string authenticationMethod = null);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user