OAuth2介绍

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OAuth2介绍相关的知识,希望对你有一定的参考价值。

参考技术A OAuth2是一个授权框架,使应用程序能够访问其它公司提供的资源,比如腾讯、阿里、华为等公司的开放平台。OAuth2为Web、桌面程序、移动程序提供了一整套的授权流程。

OAuth一共定义了4个角色:

1、 client 请求 resource owner 授予权限。
2、 resource owner 同意授权,并且将授权许可证颁发给 client 。
3、 client 通过身份验证和授权许可证来向 authorization server 请求 access token 。
4、 authorization server 在验证 client 身份和授权许可证有效后,向 client 颁发 access token 。
5、 client 通过 access token 访问 resource server 上受保护的资源。
6、 resource server 在验证 access token 的有效性后,返回受保护的资源。
以上流程是一个基本的授权访问流程,不过根据授权方式不同流程会有差异。下面将介绍OAuth2的4种授权方式。

OAuth2一共定义了4种授权模式,另外还定义了一个机制用来定义额外的授权模式。这里主要介绍4种基本的授权模式:

(A) client 通过用户代理将用户引导至授权页面
(B) authorization server 验证 resource owner 身份,并且确定 resource owner 是授予还是拒绝 client 的 access 请求
(C)如果 resource owner 允许 client 访问, authorization server 将用户代理重定向到 client 请求时提供的 redirection URI ,同时附上 authorization code
(D) client 使用 authorization code ,向 authorization server 的 token endpoint 请求 access token 。请求时可以附带(C)中的 redirection URI (用于验证你提交的URI跟 client 注册的URI是否一致)
(E) authorization server 验证 client 身份和 authorization code 以及 redirection URI 。如果验证有效, authorization server 返回 access token 和 refresh token (可选项)

(A) client 通过用户代理将用户引导至授权页面
(B) authorization server 验证 resource owner 身份,并且确定 resource owner 是授予还是拒绝 client 的 access 请求
(C)如果 resource owner 允许 client 访问, authorization server 将引导用户代理重定向到 client 请求时提供的 redirection URI ,同时附上 URI fragment 。 URI fragment 包括了 access token
(D)用户代理通过向虚拟主机(www、FTP、Email等空间服务)请求 client 资源(客户端自己的资源)来进行重定向
(E)虚拟主机的 client 资源返回一个web页面,该页面可以访问完整的 redirection URI 以及包含了 access token 的 URI fragment 。
(F)用户代理运行web页面中的 script 脚本,用来提取 URI fragment 中的 access token
(G)用户代理将 access token 发送给 client

(A) resource owner 向 client 提供账号和密码
(B) client 通过 resource owner 的账号和密码来向 authorization server 请求获取 access token
(C) authorization server 在验证了 client 身份以及 resource owner 的账号和密码有效后,向 client 颁发 access token

(A) client 通过 authorization server 进行身份验证,并请求 access token
(B) authorization server 在验证了 client 身份有效后,向 client 颁发 access token

以上是关于OAuth2介绍的主要内容,如果未能解决你的问题,请参考以下文章

Spring Security 与 OAuth2(介绍)

OAuth2之介绍及授权方式

Spring Security 与 OAuth2 介绍

Spring Security 与 OAuth2 介绍

Oauth2详解-介绍(一)

OAuth2.0介绍