[PR #5283] [MERGED] feat(sso): add option to provide login hint #31502

Closed
opened 2026-04-17 22:23:57 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5283
Author: @tnkuehne
Created: 10/13/2025
Status: Merged
Merged: 10/15/2025
Merged by: @Bekacru

Base: canaryHead: feat/sso-login-hint


📝 Commits (3)

📊 Changes

3 files changed (+32 additions, -0 deletions)

View changed files

📝 docs/content/docs/plugins/sso.mdx (+16 -0)
📝 packages/sso/src/index.ts (+13 -0)
📝 packages/sso/src/oidc.test.ts (+3 -0)

📄 Description

Hey, thanks for such a great library.

This PR introduces the option to add a login hint to SSO sign-in.

Why?

When I wanted to test my app for a different user within the same SSO provider, I signed out the first one and tried signing in the second user, but landed in my app as the first user. This is, of course, not a behavior someone expects.

Using a login hint will prevent this and will even make the user experience nicer.

What changed?

Added an optional parameter loginHint that can be given, for example, the email or username. When signIn.sso is called with the email parameter, the email will automatically be used as a login hint.

Source

https://openid.net/specs/openid-connect-core-1_0.html#:~:text=login_hint

OPTIONAL. Hint to the Authorization Server about the login identifier the End-User might use to log in (if necessary). This hint can be used by an RP if it first asks the End-User for their e-mail address (or other identifier) and then wants to pass that value as a hint to the discovered authorization service. It is RECOMMENDED that the hint value match the value used for discovery. This value MAY also be a phone number in the format specified for the phone_number Claim. The use of this parameter is left to the OP's discretion.


Summary by cubic

Adds login hint support to SSO sign-in to direct the identity provider to the intended user and avoid signing in the previous user. For OIDC, if you pass email and omit loginHint, we now send the email as login_hint automatically.

  • New Features
    • signIn.sso accepts loginHint (e.g., email or identifier).
    • OIDC: email is used as login_hint when loginHint is not provided; SAML unchanged.
    • Docs updated with examples and notes.
    • Tests added to ensure login_hint is included in the OIDC authorization URL.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5283 **Author:** [@tnkuehne](https://github.com/tnkuehne) **Created:** 10/13/2025 **Status:** ✅ Merged **Merged:** 10/15/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/sso-login-hint` --- ### 📝 Commits (3) - [`892e1a5`](https://github.com/better-auth/better-auth/commit/892e1a5c12bbaf669f5b56f3d2798f8df362ae56) feat(sso): add option to provide login hint - [`409e6a6`](https://github.com/better-auth/better-auth/commit/409e6a6008bd1e27bfe00fa301ad6d8292d35d89) chore: add tests - [`0646266`](https://github.com/better-auth/better-auth/commit/064626676e7c14bb345e165061321882b74f4f8d) chore: cleanup ### 📊 Changes **3 files changed** (+32 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/sso.mdx` (+16 -0) 📝 `packages/sso/src/index.ts` (+13 -0) 📝 `packages/sso/src/oidc.test.ts` (+3 -0) </details> ### 📄 Description Hey, thanks for such a great library. This PR introduces the option to add a login hint to SSO sign-in. ### Why? When I wanted to test my app for a different user within the same SSO provider, I signed out the first one and tried signing in the second user, but landed in my app as the first user. This is, of course, not a behavior someone expects. Using a login hint will prevent this and will even make the user experience nicer. ### What changed? Added an optional parameter `loginHint` that can be given, for example, the email or username. When `signIn.sso` is called with the email parameter, the email will automatically be used as a login hint. ### Source [https://openid.net/specs/openid-connect-core-1_0.html#:~:text=login_hint](https://openid.net/specs/openid-connect-core-1_0.html#:~:text=login_hint) > OPTIONAL. Hint to the Authorization Server about the login identifier the End-User might use to log in (if necessary). This hint can be used by an RP if it first asks the End-User for their e-mail address (or other identifier) and then wants to pass that value as a hint to the discovered authorization service. It is RECOMMENDED that the hint value match the value used for discovery. This value MAY also be a phone number in the format specified for the phone_number Claim. The use of this parameter is left to the OP's discretion. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds login hint support to SSO sign-in to direct the identity provider to the intended user and avoid signing in the previous user. For OIDC, if you pass email and omit loginHint, we now send the email as login_hint automatically. - **New Features** - signIn.sso accepts loginHint (e.g., email or identifier). - OIDC: email is used as login_hint when loginHint is not provided; SAML unchanged. - Docs updated with examples and notes. - Tests added to ensure login_hint is included in the OIDC authorization URL. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:23:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#31502