Skip to content

Commit 2b46579

Browse files
odelcroimcalinghee
andauthored
Add support for login_hint in authorization url generation (#4943)
* add login_hint to authorization url generation Signed-off-by: olivier <[email protected]> Signed-off-by: olivier <[email protected]> fix lint Signed-off-by: olivier <[email protected]> * update doc * fix linter --------- Signed-off-by: olivier <[email protected]> Co-authored-by: mcalinghee <[email protected]>
1 parent 6d42ed3 commit 2b46579

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

spec/unit/oidc/authorize.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,23 @@ describe("oidc authorization", () => {
164164

165165
expect(authUrl.searchParams.get("prompt")).toEqual("create");
166166
});
167+
168+
it("should generate url with login_hint", async () => {
169+
const nonce = "abc123";
170+
171+
const authUrl = new URL(
172+
await generateOidcAuthorizationUrl({
173+
metadata: delegatedAuthConfig,
174+
homeserverUrl: baseUrl,
175+
clientId,
176+
redirectUri: baseUrl,
177+
nonce,
178+
loginHint: "login1234",
179+
}),
180+
);
181+
182+
expect(authUrl.searchParams.get("login_hint")).toEqual("login1234");
183+
});
167184
});
168185

169186
describe("completeAuthorizationCodeGrant", () => {

src/oidc/authorize.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ export const generateAuthorizationUrl = async (
125125
* @param prompt - indicates to the OP which flow the user should see - eg login or registration
126126
* See https://openid.net/specs/openid-connect-prompt-create-1_0.html#name-prompt-parameter
127127
* @param urlState - value to append to the opaque state identifier to uniquely identify the callback
128+
* @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.
129+
* See {@link https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest OIDC core 3.1.2.1}.
128130
* @returns a Promise with the url as a string
129131
*/
130132
export const generateOidcAuthorizationUrl = async ({
@@ -136,6 +138,7 @@ export const generateOidcAuthorizationUrl = async ({
136138
nonce,
137139
prompt,
138140
urlState,
141+
loginHint,
139142
}: {
140143
clientId: string;
141144
metadata: ValidatedAuthMetadata;
@@ -145,6 +148,7 @@ export const generateOidcAuthorizationUrl = async ({
145148
nonce: string;
146149
prompt?: string;
147150
urlState?: string;
151+
loginHint?: string;
148152
}): Promise<string> => {
149153
const scope = generateScope();
150154
const oidcClient = new OidcClient({
@@ -163,6 +167,7 @@ export const generateOidcAuthorizationUrl = async ({
163167
nonce,
164168
prompt,
165169
url_state: urlState,
170+
login_hint: loginHint,
166171
});
167172

168173
return request.url;

0 commit comments

Comments
 (0)