跨应用单点登录
了解 OAuth2 和 OpenID Connect 如何实现单点登录,让用户只需验证一次身份即可无缝访问多个应用。
跨应用单点登录 是 CoddyKit 上的免费 OAuth2 & OpenID Connect Deep Dive 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 OAuth2 & OpenID Connect Deep Dive 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 OAuth2 & OpenID Connect Deep Dive 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What Is SSO?
Single Sign-On lets a user authenticate once with a central identity provider and then access many applications without logging in again. OpenID Connect is the modern foundation for web and mobile SSO.
The Central Session
The magic lives at the OpenID Provider (OP). When the user logs in, the OP establishes its own session (often a cookie). Each app relies on that central session rather than maintaining its own credentials.
First App Login
App A redirects the user to the OP's /authorize endpoint. The user enters credentials, the OP sets its session cookie, and returns an authorization code to App A, which exchanges it for tokens.
Second App: Silent Login
Later the user opens App B, which also redirects to /authorize. Because the OP session cookie already exists, the OP recognizes the user and returns a code without prompting for credentials again. That is the SSO experience.
prompt=none
To check silently whether a session exists, apps can use prompt=none. The OP either returns a code immediately or an error like login_required if no session is present.
GET /authorize?response_type=code
&client_id=appB&scope=openid
&redirect_uri=https://b.example.com/cb
&prompt=noneForcing Re-authentication
Conversely, sensitive operations can require a fresh login with prompt=login or a max_age constraint, overriding the SSO session for that request.
Identity Provider Federation
The OP itself may federate to upstream providers (corporate IdP, Google, social logins). To the apps it still looks like one OP, but the OP brokers authentication to the chosen source. This centralizes policy and simplifies clients.
Single Logout
SSO needs Single Logout too: when the user signs out of one app, related sessions should end. OIDC offers front-channel and back-channel logout to notify participating apps and clear the central session.
Session Token Lifetimes
Balance convenience and security: short access tokens with refresh tokens for ongoing access, and an OP session lifetime that matches your risk tolerance. Long SSO sessions are convenient but widen the impact of a compromised device.
Native and Mobile SSO
On mobile, SSO uses the system browser (ASWebAuthenticationSession / Custom Tabs) so the OP cookie is shared across apps. Embedded WebViews break SSO and are discouraged for security and usability reasons.
Benefits and Risks
SSO improves UX, centralizes MFA and auditing, and reduces password fatigue. The trade-off: the OP becomes a high-value target, so it must be hardened, monitored, and protected with strong authentication.
Quick Check
Test your SSO understanding.
Recap
Single Sign-On centralizes authentication at the OpenID Provider.
- The OP session lets subsequent apps log in silently.
prompt=nonechecks for a session;prompt=login/max_ageforce re-auth.- Single Logout coordinates ending sessions across apps.
- Use the system browser, not embedded WebViews, for mobile SSO.
用 AI 导师学习 OAuth2 & OpenID Connect Deep Dive — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「跨应用单点登录」课时是免费的吗?
是的 — 「跨应用单点登录」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 OAuth2 & OpenID Connect Deep Dive 课程的其余内容,请升级到 CoddyKit PRO。 OAuth2 & OpenID Connect Deep Dive 课程共包含 4 节课。
「跨应用单点登录」这节课中我会学到什么?
了解 OAuth2 和 OpenID Connect 如何实现单点登录,让用户只需验证一次身份即可无缝访问多个应用。 你通过在浏览器中直接运行的动手代码来练习 OAuth2 & OpenID Connect Deep Dive,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 OAuth2 & OpenID Connect Deep Dive 需要有经验吗?
无需任何先前经验。CoddyKit 上的 OAuth2 & OpenID Connect Deep Dive 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「跨应用单点登录」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 OAuth2 & OpenID Connect Deep Dive 课中编写并运行代码吗?
能。每节 OAuth2 & OpenID Connect Deep Dive 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。