1- using IdentityModel ;
1+ using System ;
2+ using System . Linq ;
3+ using System . Security . Claims ;
4+ using System . Text . Encodings . Web ;
5+ using System . Threading . Tasks ;
6+ using IdentityModel ;
27using IdentityServer4 ;
38using IdentityServer4 . Models ;
49using IdentityServer4 . Services ;
1116using Microsoft . eShopOnContainers . Services . Identity . API . Models . AccountViewModels ;
1217using Microsoft . eShopOnContainers . Services . Identity . API . Services ;
1318using Microsoft . Extensions . Logging ;
14- using System ;
15- using System . Linq ;
16- using System . Security . Claims ;
17- using System . Text . Encodings . Web ;
18- using System . Threading . Tasks ;
1919
2020namespace Microsoft . eShopOnContainers . Services . Identity . API . Controllers
2121{
@@ -79,9 +79,16 @@ public async Task<IActionResult> Login(LoginViewModel model)
7979 if ( ModelState . IsValid )
8080 {
8181 var user = await _loginService . FindByUsername ( model . Email ) ;
82+
8283 if ( await _loginService . ValidateCredentials ( user , model . Password ) )
8384 {
84- AuthenticationProperties props = null ;
85+ var props = new AuthenticationProperties
86+ {
87+ ExpiresUtc = DateTimeOffset . UtcNow . AddHours ( 2 ) ,
88+ AllowRefresh = true ,
89+ RedirectUri = model . ReturnUrl
90+ } ;
91+
8592 if ( model . RememberMe )
8693 {
8794 props = new AuthenticationProperties
@@ -91,8 +98,8 @@ public async Task<IActionResult> Login(LoginViewModel model)
9198 } ;
9299 } ;
93100
94- await _loginService . SignIn ( user ) ;
95-
101+ await _loginService . SignInAsync ( user , props ) ;
102+
96103 // make sure the returnUrl is still valid, and if yes - redirect back to authorize endpoint
97104 if ( _interaction . IsValidReturnUrl ( model . ReturnUrl ) )
98105 {
@@ -113,7 +120,7 @@ public async Task<IActionResult> Login(LoginViewModel model)
113120 return View ( vm ) ;
114121 }
115122
116- async Task < LoginViewModel > BuildLoginViewModelAsync ( string returnUrl , AuthorizationRequest context )
123+ private async Task < LoginViewModel > BuildLoginViewModelAsync ( string returnUrl , AuthorizationRequest context )
117124 {
118125 var allowLocal = true ;
119126 if ( context ? . ClientId != null )
@@ -132,7 +139,7 @@ async Task<LoginViewModel> BuildLoginViewModelAsync(string returnUrl, Authorizat
132139 } ;
133140 }
134141
135- async Task < LoginViewModel > BuildLoginViewModelAsync ( LoginViewModel model )
142+ private async Task < LoginViewModel > BuildLoginViewModelAsync ( LoginViewModel model )
136143 {
137144 var context = await _interaction . GetAuthorizationContextAsync ( model . ReturnUrl ) ;
138145 var vm = await BuildLoginViewModelAsync ( model . ReturnUrl , context ) ;
@@ -193,7 +200,7 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
193200
194201 try
195202 {
196-
203+
197204 // hack: try/catch to handle social providers that throw
198205 await HttpContext . SignOutAsync ( idp , new AuthenticationProperties
199206 {
0 commit comments