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
目录
相关文章
|
Kubernetes 关系型数据库 MySQL
k8s教程(基础篇)-入门及案例
k8s教程(基础篇)-入门及案例
5057 0
|
移动开发 缓存 JavaScript
2021最新阿里代码规范(前端篇)
2021最新阿里代码规范(前端篇)
59296 11
2021最新阿里代码规范(前端篇)
|
8月前
|
存储 安全 前端开发
CC&LG实践|基于 LangGraph 一步步实现 Claude-Code 核心设计
本文旨在深入剖析 Claude-Code 的核心设计思想与关键技术实现,逆向分析其功能模块,结合 LangGraph 框架的能力,系统性地演示如何从一个最基础的 ReAct Agent 出发,逐步构建一个功能完备的简版 Claude-Code。
4723 19
CC&LG实践|基于 LangGraph 一步步实现 Claude-Code 核心设计
|
12月前
|
人工智能 负载均衡 Java
Spring AI Alibaba 发布企业级 MCP 分布式部署方案
本文介绍了Spring AI Alibaba MCP的开发与应用,旨在解决企业级AI Agent在分布式环境下的部署和动态更新问题。通过集成Nacos,Spring AI Alibaba实现了流量负载均衡及节点变更动态感知等功能。开发者可方便地将企业内部业务系统发布为MCP服务或开发自己的AI Agent。文章详细描述了如何通过代理应用接入存量业务系统,以及全新MCP服务的开发流程,并提供了完整的配置示例和源码链接。未来,Spring AI Alibaba计划结合Nacos3的mcp-registry与mcp-router能力,进一步优化Agent开发体验。
3729 14
|
存储 安全 数据安全/隐私保护
OAuth 2.0 的授权机制
【10月更文挑战第5天】
1294 2