From 2912ab90791489121664a1258db0a6f468d74562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Gon=C3=A7alves?= Date: Tue, 29 Apr 2025 14:29:41 +0100 Subject: [PATCH 1/3] Add support for extra parameters in refresh requests --- CHANGELOG.md | 4 ++++ src/oauth-agent-client.ts | 16 ++++++++++------ src/types.ts | 12 +++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4601234..ba2c170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Token Handler Assistant Changelog +## [Pending] + +- Add support for extra parameters in refresh requests + ## [1.1.0] - 2024-08-12 - Send `token-handler-version` header in all requests diff --git a/src/oauth-agent-client.ts b/src/oauth-agent-client.ts index f39d27c..67a5128 100644 --- a/src/oauth-agent-client.ts +++ b/src/oauth-agent-client.ts @@ -16,6 +16,7 @@ import { EndLoginRequest, LogoutResponse, OAuthAgentRemoteError, + RefreshRequest, RefreshResponse, SessionResponse, StartLoginRequest, @@ -48,13 +49,16 @@ export class OAuthAgentClient { /** * Refreshes the access token. Calls the `/refresh` endpoint. + * + * @param request the refresh request possibly containing extra parameters * * @return the refresh token response possibly containing the new access token's expiration time - * + * * @throws OAuthAgentRemoteError when OAuth Agent responded with an error */ - async refresh(): Promise { - const refreshResponse = await this.fetch("POST", "refresh") + async refresh(request?: RefreshRequest): Promise { + const urlSearchParams = this.toUrlSearchParams(request?.extraRefreshParameters) + const refreshResponse = await this.fetch("POST", "refresh", urlSearchParams) return { accessTokenExpiresIn: refreshResponse.access_token_expires_in @@ -162,7 +166,7 @@ export class OAuthAgentClient { } - private toUrlSearchParams(data: {[key: string]: string; } | undefined): URLSearchParams { + private toUrlSearchParams(data: { [key: string]: string; } | undefined): URLSearchParams { if (!data) { return new URLSearchParams() } @@ -170,12 +174,12 @@ export class OAuthAgentClient { } private async fetch(method: string, path: string, content?: URLSearchParams): Promise { - const headers= { + const headers = { accept: 'application/json', 'token-handler-version': '1' } as Record - if (path == 'login/start' || path == 'login/end') { + if (content && content.size !== 0) { headers["content-type"] = 'application/x-www-form-urlencoded' } diff --git a/src/types.ts b/src/types.ts index eb2327d..4afcc89 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,7 +17,6 @@ * (such as `scope`, `login_hint` or `ui_locales`). These parameters will be used in the authorization request. * Each parameter has to be explicitly allowed in the configuration of the token handler application * in the Curity server. - * */ export interface StartLoginRequest { readonly extraAuthorizationParameters?: { [key: string]: string }; @@ -54,6 +53,17 @@ export interface SessionResponse { readonly accessTokenExpiresIn?: number; } +/** + * Passed to {@link OAuthAgentClient#refresh} function. + */ +export interface RefreshRequest { + /** + * Extra parameters to be used in the token refresh request. + * Each parameter has to be explicitly allowed in the configuration of the token handler application + * in the Curity server. + */ + readonly extraRefreshParameters?: { [key: string]: string }; +} /** * Returned from the {@link OAuthAgentClient#refresh} function. Contains: From 631fbd7162778793b2448de8b48c428ca1d43bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Gon=C3=A7alves?= Date: Tue, 6 May 2025 09:07:53 +0100 Subject: [PATCH 2/3] Export new type on index file --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 9855596..70378e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,5 +12,5 @@ * limitations under the License. */ -export {StartLoginRequest, StartLoginResponse, EndLoginRequest, SessionResponse, RefreshResponse, LogoutResponse, OAuthAgentRemoteError} from './types' +export {StartLoginRequest, StartLoginResponse, EndLoginRequest, SessionResponse, RefreshRequest, RefreshResponse, LogoutResponse, OAuthAgentRemoteError} from './types' export {Configuration, OAuthAgentClient} from './oauth-agent-client' \ No newline at end of file From c89a17d3bc11afa93bb411904dd3eadd6b291e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Gon=C3=A7alves?= Date: Tue, 6 May 2025 09:12:42 +0100 Subject: [PATCH 3/3] Prepare for 1.2.0 release --- CHANGELOG.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba2c170..f697c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Token Handler Assistant Changelog -## [Pending] +## [1.2.0] - 2025-05-06 - Add support for extra parameters in refresh requests diff --git a/package-lock.json b/package-lock.json index 0829e75..8fb51e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@curity/token-handler-js-assistant", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@curity/token-handler-js-assistant", - "version": "1.1.0", + "version": "1.2.0", "license": "Apache-2.0", "devDependencies": { "@types/jest": "^29.5.12", diff --git a/package.json b/package.json index 6d01060..4f7fada 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curity/token-handler-js-assistant", - "version": "1.1.0", + "version": "1.2.0", "description": "Curity Token Handler JavaScript helper library", "main": "lib/token-handler-assistant-lib.js", "types": "lib/index.d.ts",