@@ -16,6 +16,7 @@ import {
1616 EndLoginRequest ,
1717 LogoutResponse ,
1818 OAuthAgentRemoteError ,
19+ RefreshRequest ,
1920 RefreshResponse ,
2021 SessionResponse ,
2122 StartLoginRequest ,
@@ -48,13 +49,16 @@ export class OAuthAgentClient {
4849
4950 /**
5051 * Refreshes the access token. Calls the `/refresh` endpoint.
52+ *
53+ * @param request the refresh request possibly containing extra parameters
5154 *
5255 * @return the refresh token response possibly containing the new access token's expiration time
53- *
56+ *
5457 * @throws OAuthAgentRemoteError when OAuth Agent responded with an error
5558 */
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 )
5862
5963 return {
6064 accessTokenExpiresIn : refreshResponse . access_token_expires_in
@@ -162,20 +166,20 @@ export class OAuthAgentClient {
162166
163167 }
164168
165- private toUrlSearchParams ( data : { [ key : string ] : string ; } | undefined ) : URLSearchParams {
169+ private toUrlSearchParams ( data : { [ key : string ] : string ; } | undefined ) : URLSearchParams {
166170 if ( ! data ) {
167171 return new URLSearchParams ( )
168172 }
169173 return new URLSearchParams ( data )
170174 }
171175
172176 private async fetch ( method : string , path : string , content ?: URLSearchParams ) : Promise < any > {
173- const headers = {
177+ const headers = {
174178 accept : 'application/json' ,
175179 'token-handler-version' : '1'
176180 } as Record < string , string >
177181
178- if ( path == 'login/start' || path == 'login/end' ) {
182+ if ( content && content . size ! == 0 ) {
179183 headers [ "content-type" ] = 'application/x-www-form-urlencoded'
180184 }
181185
0 commit comments