Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to supply user-defined state key. #168

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/smart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export async function authorize(
scope = "",
clientId,
completeInTarget,
clientPrivateJwk
clientPrivateJwk,
stateKey
} = params;

const storage = env.getStorage();
Expand Down Expand Up @@ -250,8 +251,9 @@ export async function authorize(
const oldKey = await storage.get(SMART_KEY);
await storage.unset(oldKey);

// create initial state
const stateKey = randomString(16);
stateKey = stateKey ?? randomString(16);

// Create initial state
const state: fhirclient.ClientState = {
clientId,
scope,
Expand Down
19 changes: 19 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,25 @@ declare namespace fhirclient {
* this setting
*/
pkceMode?: PkceMode;

/**
* An opaque value used by the client to maintain state between the request and callback.
*
* If stateKey is not specified, one will be generated automatically.
*
* The authorization server includes this value when redirecting the user-agent back to the
* client.
*
* It's important to ensure that no sensitive information is included in the state
* parameter because it could be saved in the browser's history or server logs. To prevent
* CSRF attacks, the state parameter should be generated with a secure random seed.
*
* From the perspective of developing client applications, the state parameter is useful
* for restoring a user's session, which might involve querying a data structure for cached
* objects specific to that user. The state parameter could refer to a user session key,
* but its purpose may vary depending on the application.
*/
stateKey?: string;
}

interface ReadyOptions {
Expand Down