Skip to content

Commit

Permalink
Merge pull request #175 from rob-a-bolton/refresh-with-client-id
Browse files Browse the repository at this point in the history
Add refreshTokenWithClientId option, to send client_id when using a refresh token
  • Loading branch information
vlad-ignatov authored Feb 17, 2025
2 parents 1e833b5 + a557ed9 commit b4f927e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,10 @@ export default class Client
// requests in parallel which may result in multiple refresh calls.
// To avoid that, we keep a reference to the current refresh task (if any).
if (!this._refreshTask) {

let body = `grant_type=refresh_token&refresh_token=${encodeURIComponent(refreshToken)}`;
if (this.environment.options.refreshTokenWithClientId) {
body += `&client_id=${this.state.clientId}`;
}
const refreshRequestOptions = {
credentials: this.environment.options.refreshTokenWithCredentials || "same-origin",
...requestOptions,
Expand All @@ -1056,7 +1059,7 @@ export default class Client
...(requestOptions.headers || {}),
"content-type": "application/x-www-form-urlencoded"
},
body: `grant_type=refresh_token&refresh_token=${encodeURIComponent(refreshToken)}`
body: body
};

// custom authorization header can be passed on manual calls
Expand Down
9 changes: 9 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ declare namespace fhirclient {
*/
refreshTokenWithCredentials?: "omit" | "include" | "same-origin";

/**
* Some OAuth implementations require the client_id to be sent
* when using a refresh token.
* Setting `FHIR.oauth2.settings.refreshTokenWithClientId = true`
* enables this behaviour, sending the "client_id" parameter in
* the refresh request body.
*/
refreshTokenWithClientId?: boolean;

// storage?: Storage | ((options?: JsonObject) => Storage);
}

Expand Down

0 comments on commit b4f927e

Please sign in to comment.