OIDC SSO - OAuth2.0的授权模式选择

简介: ## 背景信息> OIDC SSO相关文档总共4篇,主要内容为对OIDC实现SSO登录流程时的各个细节和相关技术的阐述:1. 《OIDC SSO - OAuth2.0的授权模式选择》2. 《[OIDC SSO - 相关SSO流程和注意事项](https://ata.alibaba-inc.com/articles/218495)》3. 《[OIDC SSO - Discovery Mech

背景信息

OIDC SSO相关文档总共4篇,主要内容为对OIDC实现SSO登录流程时的各个细节和相关技术的阐述:1. 《OIDC SSO - OAuth2.0的授权模式选择》

基于OIDC实现SSO时,可以选择不同的OAuth2授权流来完成整个SSO流程。
本文档对其进行了总结,其中大部分内容从Okta官方文档Authing官方文档翻译而来,然后增加了部分自己认为重要的提示知识。
引用链接:https://docs.authing.cn/v2/concepts/oidc/choose-flow.html
https://developer.okta.com/docs/concepts/oauth-openid/#is-your-client-a-spa-or-native
image.pngimage.png


应用类型 OAuth2 流
Server-side Application Authorization Code Flow
Single-Page Application Authorization Code Flow with PKCE or Implicit Flow
Native Application Authorization Code Flow with PKCE
Trusted Resource Owner Password Flow
Server Client Credentials
语雀文档格式更好看一点: https://yuque.antfin.com/docs/share/bf4b2431-bfaa-42e4-aaeb-b581ec454b40?# 《OIDC SSO - OAuth 2.0 Authorization Framework》

OAuth2各个流时序图说明

Authorization Code Flow - 授权码流


Authorization Code流支持返回id token、refresh token;
如果Response type是code+token,这种直接返回的access token和code来换取的access token,同时有效。

Authorization Code Flow 简化版本

Authorization Code With PKCE Flow增强


具体参考Okta Blog:https://developer.okta.com/blog/2019/08/22/okta-authjs-pkce
推荐用户用Authorization Code With PKCE Flow 而不是Implicit Flow

image.png

Implicit Flow - 隐式流


隐式流不支持返回Refresh Token;
OIDC规范要求implicit flow中的Authentication request必须指定nonce;

Client Credential Flow

适用于M2M的纯后台交互模式;
不支持返回refresh token;

Resource Owner Password Flow - 密码模式


IDaaS不支持这种模式
密码模式适用于你既掌握应用程序又掌握应用所需资源的场景。密码模式要求应用能够安全存储密钥,并且能够被信任地存储资源所有者的账密。一般常见于自家应用使用自家的资源。密码模式不需要重定向跳转,只需要携带用户账密访问 Token 端点。

OAuth 2.0 Token Exchange - Client Credential Based

RFC-8693: OAuth 2.0 Token Exchange
允许一个Client通过扮演终端用户角色身份方式获取access_token(类似阿里云RAM角色扮演)。
通俗来讲就是一个Client A 扮演 User B访问 Service C;另外OAuth 2.0 STS同时支持扮演和委托,取决于是否存在actor_token。
STS解决的问题举例: https://www.scottbrady91.com/oauth/delegation-patterns-for-oauth-20

image.png

认证请求参数 类型 取值
grant_type REQUIRED urn:ietf:params:oauth:grant-type:token-exchange
resource OPTIONAL 要访问的Resource,认证服务能够映射成resource uri
audience OPTIONAL 代表这次security token的逻辑名字
scope OPTIONAL 授权访问范围
requested_token_type OPTIONAL token类型,见下表
subject_token REQUIRED 要扮演的用户实体身份标识
subject_token_type REQUIRED token类型,见下表
actor_token OPTIONAL 扮演用户实体身份的参与者标识
actor_token_type OPTIONAL token类型,见下表
认证返回参数 类型 取值
access_token REQUIRED urn:ietf:params:oauth:grant-type:token-exchange
issued_token_type REQUIRED 签名的security token标识
urn:ietf:params:oauth:token-type:access_token
token_type REQUIRED 这次签发的access_token怎么使用
expires_in RECOMMENDED 过期时间 单位second
scope OPTIONAL 授权访问范围
refresh_token OPTIONAL 刷新token
上述Token type可选的取值
urn:ietf:params:oauth:token-type:access_token
urn:ietf:params:oauth:token-type:refresh_token
urn:ietf:params:oauth:token-type:id_token
urn:ietf:params:oauth:token-type:saml1
urn:ietf:params:oauth:token-type:saml2
urn:ietf:params:oauth:token-type:jwt

其它重要信息

Hybrid Flow


This section describes how to perform authentication using the Hybrid Flow. When using the Hybrid Flow, some tokens are returned from the Authorization Endpoint and others are returned from the Token Endpoint. The mechanisms for returning tokens in the Hybrid Flow are specified in OAuth 2.0 Multiple Response Type Encoding Practices [OAuth.Responses].

也就是在一次授权流中可以支持即返回code,也返回access_token和id_token数据;具体可以看下response type在三种授权流中的value可选值;

OIDC中三种流支持的各个特性表格

特性 Authorization Coed Flow Implicit Flow Hybrid Flow
All tokens returned from Authorization Endpoint
所有token全部从授权端点返回
yes
All tokens returned from Token Endpoint
所有token全部从token端点返回
yes
Tokens not revealed to User Agent
token不会在用户前端暴露
yes
Client can be authenticated
客户端可以被认证
yes yes
Refresh Token possible
能不能拿到Refresh Token
yes yes
Communication in one round trip
一次交互完成通信
yes
Most communication server-to-server
大部分的通信都是服务器对服务器
yes varies

OIDC中三种流中支持的response type


多response type定义规范:https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html

"response type" value Authorization Coed Flow Implicit Flow Hybrid Flow
code yes
id_token yes
id_token token yes
code id_token yes
code token yes
code id_token token yes

参考信息

  1. Okta官方文档 - OAuth 2.0 and OpenID Connect Overview : https://developer.okta.com/docs/concepts/oauth-openid/#what-kind-of-client-are-you-building
  2. Authing官方文档-选择OAuth2授权模式: https://docs.authing.cn/v2/concepts/oidc/choose-flow.html
  3. OIDC Core:https://openid.net/specs/openid-connect-core-1_0.html
  4. OAuth 2.0 Authorization Framework - RFC 6749: https://www.rfc-editor.org/rfc/pdfrfc/rfc6749.txt.pdf
  5. PKCE By OAuth 2.0 Client - RFC 7636: https://www.rfc-editor.org/rfc/pdfrfc/rfc7636.txt.pdf
  6. OAuth 2.0 Token Exchange - RFC 8693:https://datatracker.ietf.org/doc/html/rfc8693
  7. Delegation Patterns for OAuth 2.0 using Token Exchange : https://www.scottbrady91.com/oauth/delegation-patterns-for-oauth-20
目录
相关文章
|
数据安全/隐私保护
关于 OAuth 2.0 统一认证授权
随着互联网的巨头大佬逐渐积累了海量的用户与数据,用户的需求越来越多样化,为了满足用户在不同平台活动的需求,平台级的厂商则需要以接口的形式开放给第三方开发者,这样满足了用户的多样性需求,也可以让自己获得利益,让数据流动起来,形成给一个良性的生态环境,最终达到用户、平台商、第三方开发者共赢。
2940 0
|
25天前
|
数据安全/隐私保护
OAuth 2.0身份验证及授权
8月更文挑战第24天
47 0
|
2月前
|
安全 前端开发 Java
实现基于OAuth2的安全认证与授权
实现基于OAuth2的安全认证与授权
|
4月前
|
安全 数据安全/隐私保护 UED
|
11月前
|
存储 数据安全/隐私保护
我对SSO单点登录和OAuth2.0的理解
单点登录(SingleSignOn,SSO),就是通过用户的一次性鉴别登录。当用户在身份认证服务器上登录一次以后,即可获得访问单点登录系统中其他关联系统和应用软件的权限,用户只需一次登录就可以访问所有相互信任的应用系统。比如我们登录了公司的OA系统之后,在页面上点击邮件系统,则无需再跳转到邮件的登录页面,点过去就直接登录成功了。
168 0
|
存储 安全 前端开发
基于OIDC的SSO单点登录
基于OIDC的SSO单点登录
474 0
|
Python
基于flask-oidc的OIDC协议授权码模式单点登录SSO实现
基于flask-oidc的OIDC协议授权码模式单点登录SSO实现
271 0
|
存储 开发框架 安全
快速理解 IdentityServer4 中的认证 & 授权
在实际的生产环境中,存在各种各样的应用程序相互访问,当用户访问 `app` 应用的时候,为了安全性考虑,通常都会要求搭配授权码或者安全令牌服务一并访问,这样可有效地对 `Server` 端的 `API` 资源起到一定程度的有效保护...
430 0
快速理解 IdentityServer4 中的认证 & 授权
|
消息中间件 前端开发 JavaScript
SSO 单点登录和 OAuth2.0 的区别和理解
SSO 单点登录和 OAuth2.0 的区别和理解
Jasny SSO是否支持OAuth认证?底层原理是什么?
Jasny SSO是否支持OAuth认证?底层原理是什么?