Skip to content

Add support for login_hint in authorization url generation #4943

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions spec/unit/oidc/authorize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ describe("oidc authorization", () => {

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

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

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

expect(authUrl.searchParams.get("login_hint")).toEqual("login1234");
});
});

describe("completeAuthorizationCodeGrant", () => {
Expand Down
5 changes: 5 additions & 0 deletions src/oidc/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export const generateAuthorizationUrl = async (
* @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
* @param urlState - value to append to the opaque state identifier to uniquely identify the callback
* @param loginHint - value to send as the `login_hint` to the OP, giving a hint about the login identifier the user might use to log in.
* See {@link https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest OIDC core 3.1.2.1}.
* @returns a Promise with the url as a string
*/
export const generateOidcAuthorizationUrl = async ({
Expand All @@ -136,6 +138,7 @@ export const generateOidcAuthorizationUrl = async ({
nonce,
prompt,
urlState,
loginHint,
}: {
clientId: string;
metadata: ValidatedAuthMetadata;
Expand All @@ -145,6 +148,7 @@ export const generateOidcAuthorizationUrl = async ({
nonce: string;
prompt?: string;
urlState?: string;
loginHint?: string;
}): Promise<string> => {
const scope = generateScope();
const oidcClient = new OidcClient({
Expand All @@ -163,6 +167,7 @@ export const generateOidcAuthorizationUrl = async ({
nonce,
prompt,
url_state: urlState,
login_hint: loginHint,
});

return request.url;
Expand Down
Loading