Skip to content

Commit

Permalink
add prompt param to OIDC auth url creation (#3794)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry authored Oct 11, 2023
1 parent c8f8fb5 commit 1de6de0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
19 changes: 19 additions & 0 deletions spec/unit/oidc/authorize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ describe("oidc authorization", () => {

expect(authUrl.searchParams.get("code_challenge")).toBeTruthy();
});

it("should generate url with create prompt", async () => {
const nonce = "abc123";

const metadata = delegatedAuthConfig.metadata;

const authUrl = new URL(
await generateOidcAuthorizationUrl({
metadata,
homeserverUrl: baseUrl,
clientId,
redirectUri: baseUrl,
nonce,
prompt: "create",
}),
);

expect(authUrl.searchParams.get("prompt")).toEqual("create");
});
});

describe("completeAuthorizationCodeGrant", () => {
Expand Down
12 changes: 10 additions & 2 deletions src/oidc/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ export const generateAuthorizationUrl = async (
* @experimental
* Generate a URL to attempt authorization with the OP
* See https://openid.net/specs/openid-connect-basic-1_0.html#CodeRequest
* @param oidcClientSettings - oidc configuration
* @param homeserverName - used as state
* @param metadata - validated metadata from OP discovery
* @param clientId - this client's id as registered with the OP
* @param homeserverUrl - used to establish the session on return from the OP
* @param identityServerUrl - used to establish the session on return from the OP
* @param nonce - state
* @param prompt - indicates to the OP which flow the user should see - eg login or registration
* See https://openid.net/specs/openid-connect-prompt-create-1_0.html#name-prompt-parameter
* @returns a Promise with the url as a string
*/
export const generateOidcAuthorizationUrl = async ({
Expand All @@ -133,13 +138,15 @@ export const generateOidcAuthorizationUrl = async ({
homeserverUrl,
identityServerUrl,
nonce,
prompt,
}: {
clientId: string;
metadata: ValidatedIssuerMetadata;
homeserverUrl: string;
identityServerUrl?: string;
redirectUri: string;
nonce: string;
prompt?: string;
}): Promise<string> => {
const scope = await generateScope();
const oidcClient = new OidcClient({
Expand All @@ -156,6 +163,7 @@ export const generateOidcAuthorizationUrl = async ({
const request = await oidcClient.createSigninRequest({
state: userState,
nonce,
prompt,
});

return request.url;
Expand Down

0 comments on commit 1de6de0

Please sign in to comment.