@@ -16,6 +16,7 @@ import {
16
16
EndLoginRequest ,
17
17
LogoutResponse ,
18
18
OAuthAgentRemoteError ,
19
+ RefreshRequest ,
19
20
RefreshResponse ,
20
21
SessionResponse ,
21
22
StartLoginRequest ,
@@ -48,13 +49,16 @@ export class OAuthAgentClient {
48
49
49
50
/**
50
51
* Refreshes the access token. Calls the `/refresh` endpoint.
52
+ *
53
+ * @param request the refresh request possibly containing extra parameters
51
54
*
52
55
* @return the refresh token response possibly containing the new access token's expiration time
53
- *
56
+ *
54
57
* @throws OAuthAgentRemoteError when OAuth Agent responded with an error
55
58
*/
56
- async refresh ( ) : Promise < RefreshResponse > {
57
- const refreshResponse = await this . fetch ( "POST" , "refresh" )
59
+ async refresh ( request ?: RefreshRequest ) : Promise < RefreshResponse > {
60
+ const urlSearchParams = this . toUrlSearchParams ( request ?. extraRefreshParameters )
61
+ const refreshResponse = await this . fetch ( "POST" , "refresh" , urlSearchParams )
58
62
59
63
return {
60
64
accessTokenExpiresIn : refreshResponse . access_token_expires_in
@@ -162,20 +166,20 @@ export class OAuthAgentClient {
162
166
163
167
}
164
168
165
- private toUrlSearchParams ( data : { [ key : string ] : string ; } | undefined ) : URLSearchParams {
169
+ private toUrlSearchParams ( data : { [ key : string ] : string ; } | undefined ) : URLSearchParams {
166
170
if ( ! data ) {
167
171
return new URLSearchParams ( )
168
172
}
169
173
return new URLSearchParams ( data )
170
174
}
171
175
172
176
private async fetch ( method : string , path : string , content ?: URLSearchParams ) : Promise < any > {
173
- const headers = {
177
+ const headers = {
174
178
accept : 'application/json' ,
175
179
'token-handler-version' : '1'
176
180
} as Record < string , string >
177
181
178
- if ( path == 'login/start' || path == 'login/end' ) {
182
+ if ( content && content . size ! == 0 ) {
179
183
headers [ "content-type" ] = 'application/x-www-form-urlencoded'
180
184
}
181
185
0 commit comments