@@ -85,28 +85,30 @@ function oidcCodeExchange(r) {
85
85
}
86
86
87
87
function oidcRefreshRequest ( r ) {
88
- // Pass the refresh token code to the /_refresh location so that it can be
88
+ // Pass the refresh token to the /_refresh location so that it can be
89
89
// proxied to the IdP in exchange for a new id_token
90
90
r . subrequest ( "/_refresh" , "token=" + r . variables . refresh_token ,
91
91
function ( reply ) {
92
- if ( reply . status == 504 ) {
93
- r . error ( "OIDC timeout connecting to IdP when sending refresh request" ) ;
94
- r . return ( 504 ) ;
95
- return ;
96
- }
97
-
98
92
if ( reply . status != 200 ) {
99
- try {
100
- var errorset = JSON . parse ( reply . responseBody ) ;
101
- if ( errorset . error ) {
102
- r . error ( "OIDC error from IdP when sending refresh request: " + errorset . error + ", " + errorset . error_description ) ;
103
- } else {
104
- r . error ( "OIDC unexpected response from IdP when sending refresh request (HTTP " + reply . status + "). " + reply . responseBody ) ;
93
+ // Refresh request failed, log the reason
94
+ var error_log = "OIDC refresh failure" ;
95
+ if ( reply . status == 504 ) {
96
+ error_log += ", timeout waiting for IdP" ;
97
+ } else if ( reply . status = 400 ) {
98
+ try {
99
+ var errorset = JSON . parse ( reply . responseBody ) ;
100
+ error_log += ": " + errorset . error + " " + errorset . error_description ;
101
+ } catch ( e ) {
102
+ error_log += ": " + reply . responseBody ;
105
103
}
106
- } catch ( e ) {
107
- r . error ( "OIDC unexpected response from IdP when sending refresh request (HTTP " + reply . status + "). " + reply . responseBody ) ;
104
+ } else {
105
+ error_log += " " + reply . status ;
108
106
}
109
- r . return ( 502 ) ;
107
+ r . error ( error_log ) ;
108
+
109
+ // Clear the refresh token, try again
110
+ r . variables . refresh_token = "-" ;
111
+ r . return ( 302 , r . variables . request_uri ) ;
110
112
return ;
111
113
}
112
114
@@ -118,20 +120,22 @@ function oidcRefreshRequest(r) {
118
120
if ( tokenset . error ) {
119
121
r . error ( "OIDC " + tokenset . error + " " + tokenset . error_description ) ;
120
122
}
121
- r . return ( 500 ) ;
123
+ r . variables . refresh_token = "-" ;
124
+ r . return ( 302 , r . variables . request_uri ) ;
122
125
return ;
123
126
}
124
127
125
128
// Send the new ID Token to auth_jwt location for validation
126
129
r . subrequest ( "/_id_token_validation" , "token=" + tokenset . id_token ,
127
130
function ( reply ) {
128
131
if ( reply . status != 204 ) {
129
- r . return ( 500 ) ; // validateIdToken() will log errors
132
+ r . variables . refresh_token = "-" ;
133
+ r . return ( 302 , r . variables . request_uri ) ;
130
134
return ;
131
135
}
132
136
133
137
// ID Token is valid, update keyval
134
- r . log ( "OIDC updating id_token" ) ;
138
+ r . log ( "OIDC refresh success, updating id_token" ) ;
135
139
r . variables . session_jwt = tokenset . id_token ; // Update key-value store
136
140
137
141
// Update refresh token (if we got a new one)
@@ -140,13 +144,13 @@ function oidcRefreshRequest(r) {
140
144
r . variables . refresh_token = tokenset . refresh_token ; // Update key-value store
141
145
}
142
146
143
- r . log ( "OIDC refresh success" ) ;
144
147
r . internalRedirect ( r . variables . request_uri ) ; // Continue processing original request
145
148
}
146
149
) ;
147
150
} catch ( e ) {
148
- r . error ( "OIDC refresh response is not JSON. " + reply . responseBody ) ;
149
- r . return ( 502 ) ;
151
+ r . variables . refresh_token = "-" ;
152
+ r . return ( 302 , r . variables . request_uri ) ;
153
+ return ;
150
154
}
151
155
}
152
156
) ;
0 commit comments