1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Security . Claims ;
5- using System . Threading . Tasks ;
1+ using Microsoft . AspNetCore . Authentication . Cookies ;
62using Microsoft . AspNetCore . Http ;
73using Microsoft . AspNetCore . Mvc . Rendering ;
4+ using Microsoft . Extensions . DependencyInjection ;
5+ using Microsoft . Extensions . Options ;
86using Olive ;
97using Olive . Microservices . Hub ;
108using Olive . Security ;
9+ using System ;
10+ using System . Collections . Generic ;
11+ using System . Linq ;
12+ using System . Security . Claims ;
13+ using System . Threading . Tasks ;
1114
1215namespace System
1316{
@@ -16,7 +19,7 @@ public static class Extensions
1619 static int Timeout => Config . Get < int > ( "Authentication:Cookie:Timeout" ) ;
1720 static int MobileTimeout => Config . Get < int > ( "Authentication:Cookie:TimeoutMobile" ) ;
1821
19- public static Task LogOn ( this PeopleService . UserInfo @this )
22+ public static async Task LogOn ( this PeopleService . UserInfo @this )
2023 {
2124 var mobile = Context . Current . Request ( ) . IsSmartPhone ( ) ;
2225
@@ -31,7 +34,26 @@ public static Task LogOn(this PeopleService.UserInfo @this)
3134
3235 TryAddJwtToken ( loggingInfo , mobile ) ;
3336
34- return loggingInfo . LogOn ( remember : mobile ) ;
37+ await loggingInfo . LogOn ( remember : mobile ) ;
38+
39+ Context . Current . Http ( ) . SetAuthHeader ( ) ;
40+ }
41+
42+ public static void SetAuthHeader ( this HttpContext httpContext )
43+ {
44+ var cookieOptions = httpContext . RequestServices . GetService < IOptionsMonitor < CookieAuthenticationOptions > > ( ) ;
45+ var cookieName = cookieOptions ? . Get ( CookieAuthenticationDefaults . AuthenticationScheme ) . Cookie . Name ;
46+
47+ if ( cookieName . IsEmpty ( ) )
48+ {
49+ return ;
50+ }
51+
52+ var authCookie = httpContext . Response . Headers [ "Set-Cookie" ]
53+ . FirstOrDefault ( h => h . StartsWith ( $ "{ cookieName } =") ) ;
54+
55+ var token = authCookie ? . Split ( ';' ) [ 0 ] . Split ( '=' ) [ 1 ] ;
56+ httpContext . Response . Headers [ "X-Auth-Token" ] = token ;
3557 }
3658
3759 public static async Task < PeopleService . UserInfo > LoadUser ( this ClaimsPrincipal principal )
0 commit comments