OpenID Connect,如果尚未登录,则无需登录表单即可重定向?
OpenID Connect, redirect without login form if not already logged in?
在 OpenID Connect 中,我希望我的用户在连接到身份提供者时自动连接到我的客户端(假设他们已经授权我的客户端应用程序)。
这是我想要的工作流程:
- USER 到达 CLIENT 主页
- USER 被重定向到 IdP(授权请求)
- 如果他已登录 IdP,他将被重定向到 CLIENT 并且 OIDC 工作流开始,然后他将登录 CLIENT
- 如果他没有登录 IdP 或者他没有授权 CLIENT 访问他的身份,IdP 的登录表单不会显示给用户并且他被重定向到 CLIENT 主页,没有登录
这就像 CAS 中的 "Gateway" 模式。
我使用授权代码流,我不想使用 Javascript 和隐式流来通过 JS 动态登录。
你知道这是否可能吗?我在规范中找不到它。
谢谢:)
您正在考虑基于 IDP 的 SSO 行为。这通常在 OpenID Connect 规范之外,并且通常绑定到您正在使用的特定身份提供者(例如:- Azure、PING 或 WSO2)。但是有一些参数可以调整此行为,例如 prompt 和 login_hint 是可选的。
来自 OpenID Connect authentication request section
prompt
Space delimited, case sensitive list of ASCII string values that
specifies whether the Authorization Server prompts the End-User for
reauthentication and consent.
有效值为 login、none、consent 和 select_account。您可以使用它们强制登录或允许 select 帐户。
login_hint
Hint to the Authorization Server about the login
identifier the End-User might use to log in (if necessary)
一个很好的例子是通过将 login_hint 传递给身份提供者来启用 SSO 行为。如果身份提供者可以根据(例如)企业 LDAP 验证身份并检测登录状态,则您可以提供无凭据登录体验。同时,您可以使用 prompt=login 强制登录,即使身份提供者持有登录会话也是如此。
或者,您可以使用 signinSilent()
。我在我的登录页面上使用了它 ngOnInit
(因为 AuthGuard 无论如何都会重定向用户登录,我认为这将是我场景中的完美位置)。
// login.ts
ngOnInit(): void {
this.authService.signinSilent().then(_ => {}).catch(_ => {});
}
// authService
public signinSilent() {
return this.userManager.signinSilent();
}
signinSilent
方法将 return 如果用户已经与 idp 进行了有效会话,则用户对象。否则它会抛出错误,可能是 login_required
.
在 OpenID Connect 中,我希望我的用户在连接到身份提供者时自动连接到我的客户端(假设他们已经授权我的客户端应用程序)。
这是我想要的工作流程:
- USER 到达 CLIENT 主页
- USER 被重定向到 IdP(授权请求)
- 如果他已登录 IdP,他将被重定向到 CLIENT 并且 OIDC 工作流开始,然后他将登录 CLIENT
- 如果他没有登录 IdP 或者他没有授权 CLIENT 访问他的身份,IdP 的登录表单不会显示给用户并且他被重定向到 CLIENT 主页,没有登录
这就像 CAS 中的 "Gateway" 模式。 我使用授权代码流,我不想使用 Javascript 和隐式流来通过 JS 动态登录。
你知道这是否可能吗?我在规范中找不到它。
谢谢:)
您正在考虑基于 IDP 的 SSO 行为。这通常在 OpenID Connect 规范之外,并且通常绑定到您正在使用的特定身份提供者(例如:- Azure、PING 或 WSO2)。但是有一些参数可以调整此行为,例如 prompt 和 login_hint 是可选的。
来自 OpenID Connect authentication request section
prompt
Space delimited, case sensitive list of ASCII string values that specifies whether the Authorization Server prompts the End-User for reauthentication and consent.
有效值为 login、none、consent 和 select_account。您可以使用它们强制登录或允许 select 帐户。
login_hint
Hint to the Authorization Server about the login identifier the End-User might use to log in (if necessary)
一个很好的例子是通过将 login_hint 传递给身份提供者来启用 SSO 行为。如果身份提供者可以根据(例如)企业 LDAP 验证身份并检测登录状态,则您可以提供无凭据登录体验。同时,您可以使用 prompt=login 强制登录,即使身份提供者持有登录会话也是如此。
或者,您可以使用 signinSilent()
。我在我的登录页面上使用了它 ngOnInit
(因为 AuthGuard 无论如何都会重定向用户登录,我认为这将是我场景中的完美位置)。
// login.ts
ngOnInit(): void {
this.authService.signinSilent().then(_ => {}).catch(_ => {});
}
// authService
public signinSilent() {
return this.userManager.signinSilent();
}
signinSilent
方法将 return 如果用户已经与 idp 进行了有效会话,则用户对象。否则它会抛出错误,可能是 login_required
.