Skip to content

Commit b9ddeaa

Browse files
committed
add login_hint to authorization url generation
Signed-off-by: olivier <[email protected]>
1 parent 56b24c0 commit b9ddeaa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ 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 - send connecting user login hint to OP
128129
* @returns a Promise with the url as a string
129130
*/
130131
export const generateOidcAuthorizationUrl = async ({
@@ -136,6 +137,7 @@ export const generateOidcAuthorizationUrl = async ({
136137
nonce,
137138
prompt,
138139
urlState,
140+
loginHint,
139141
}: {
140142
clientId: string;
141143
metadata: ValidatedAuthMetadata;
@@ -145,6 +147,7 @@ export const generateOidcAuthorizationUrl = async ({
145147
nonce: string;
146148
prompt?: string;
147149
urlState?: string;
150+
loginHint?: string;
148151
}): Promise<string> => {
149152
const scope = generateScope();
150153
const oidcClient = new OidcClient({
@@ -163,6 +166,7 @@ export const generateOidcAuthorizationUrl = async ({
163166
nonce,
164167
prompt,
165168
url_state: urlState,
169+
login_hint:loginHint
166170
});
167171

168172
return request.url;

0 commit comments

Comments
 (0)