Skip to content

Commit 2912ab9

Browse files
committed
Add support for extra parameters in refresh requests
1 parent 242fe4a commit 2912ab9

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Token Handler Assistant Changelog
22

3+
## [Pending]
4+
5+
- Add support for extra parameters in refresh requests
6+
37
## [1.1.0] - 2024-08-12
48

59
- Send `token-handler-version` header in all requests

src/oauth-agent-client.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* (such as `scope`, `login_hint` or `ui_locales`). These parameters will be used in the authorization request.
1818
* Each parameter has to be explicitly allowed in the configuration of the token handler application
1919
* in the Curity server.
20-
*
2120
*/
2221
export interface StartLoginRequest {
2322
readonly extraAuthorizationParameters?: { [key: string]: string };
@@ -54,6 +53,17 @@ export interface SessionResponse {
5453
readonly accessTokenExpiresIn?: number;
5554
}
5655

56+
/**
57+
* Passed to {@link OAuthAgentClient#refresh} function.
58+
*/
59+
export interface RefreshRequest {
60+
/**
61+
* Extra parameters to be used in the token refresh request.
62+
* Each parameter has to be explicitly allowed in the configuration of the token handler application
63+
* in the Curity server.
64+
*/
65+
readonly extraRefreshParameters?: { [key: string]: string };
66+
}
5767

5868
/**
5969
* Returned from the {@link OAuthAgentClient#refresh} function. Contains:

0 commit comments

Comments
 (0)