Skip to content

Commit 78cd483

Browse files
Merge pull request #11 from curityio/extra-refresh-params
Add support for extra parameters in refresh requests
2 parents 242fe4a + c89a17d commit 78cd483

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
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+
## [1.2.0] - 2025-05-06
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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curity/token-handler-js-assistant",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Curity Token Handler JavaScript helper library",
55
"main": "lib/token-handler-assistant-lib.js",
66
"types": "lib/index.d.ts",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
* limitations under the License.
1313
*/
1414

15-
export {StartLoginRequest, StartLoginResponse, EndLoginRequest, SessionResponse, RefreshResponse, LogoutResponse, OAuthAgentRemoteError} from './types'
15+
export {StartLoginRequest, StartLoginResponse, EndLoginRequest, SessionResponse, RefreshRequest, RefreshResponse, LogoutResponse, OAuthAgentRemoteError} from './types'
1616
export {Configuration, OAuthAgentClient} from './oauth-agent-client'

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)