@@ -7,7 +7,30 @@ var newSession = false; // Used by oidcAuth() and validateIdToken()
7
7
8
8
export default { auth, codeExchange, validateIdToken, logout} ;
9
9
10
- function auth ( r ) {
10
+ function retryOriginalRequest ( r ) {
11
+ delete r . headersOut [ "WWW-Authenticate" ] ; // Remove evidence of original failed auth_jwt
12
+ r . internalRedirect ( r . variables . uri + r . variables . is_args + ( r . variables . args || '' ) ) ;
13
+ }
14
+
15
+ // If the ID token has not been synced yet, poll the variable every 100ms until
16
+ // get a value or after a timeout.
17
+ function waitForSessionSync ( r , timeLeft ) {
18
+ if ( r . variables . session_jwt ) {
19
+ retryOriginalRequest ( r ) ;
20
+ } else if ( timeLeft > 0 ) {
21
+ setTimeout ( waitForSessionSync , 100 , r , timeLeft - 100 ) ;
22
+ } else {
23
+ auth ( r , true ) ;
24
+ }
25
+ }
26
+
27
+ function auth ( r , afterSyncCheck ) {
28
+ // If a cookie was sent but the ID token is not in the key-value database, wait for the token to be in sync.
29
+ if ( r . variables . cookie_auth_token && ! r . variables . session_jwt && ! afterSyncCheck && r . variables . zone_sync_leeway > 0 ) {
30
+ waitForSessionSync ( r , r . variables . zone_sync_leeway ) ;
31
+ return ;
32
+ }
33
+
11
34
if ( ! r . variables . refresh_token || r . variables . refresh_token == "-" ) {
12
35
newSession = true ;
13
36
@@ -88,8 +111,7 @@ function auth(r) {
88
111
r . variables . refresh_token = tokenset . refresh_token ; // Update key-value store
89
112
}
90
113
91
- delete r . headersOut [ "WWW-Authenticate" ] ; // Remove evidence of original failed auth_jwt
92
- r . internalRedirect ( r . variables . request_uri ) ; // Continue processing original request
114
+ retryOriginalRequest ( r ) ; // Continue processing original request
93
115
}
94
116
) ;
95
117
} catch ( e ) {
0 commit comments