OAUTH2核心参数说明
grant_type参数说明表格:
grant_type
|
说明
|
authorization_code
|
标准的Server授权模式
|
password
|
基于用户密码的授权模式
|
client_credentials
|
基于APP密钥的授权模式
|
refresh_token
|
刷新accessToken
|
response_type参数说明表格:
response_type
|
说明
|
code
|
标准的Server授权模式响应模式
|
token
|
脚本的授权响应模式,直接返回token,需要对回调进行校验
|
OAUTH2各种请求流程
Authorization Code(标准请求流程,必须实现)
标准的的Server授权模式,与目前开放平台的Session机制很像。
APP首先发送获取code请求
GET /authorize?response_type=code&client_id=s6BhdRkqt3&
redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
Host: server.example.com
容器返回code
HTTP/1.1 302 Found
Location: https://client.example.com/cb?code=i1WsRn1uB1
APP根据code发送获取token请求
POST /token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&client_id=s6BhdRkqt3&
client_secret=gX1fBat3bV&code=i1WsRn1uB1&
redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
容器直接返回token
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token":"SlAV32hkKG",
"token_type":"example",
"expires_in":3600,
"refresh_token":"8xLOxBtZp8",
"example_parameter":"example-value"
}
Implicit Grant(直接发放模式)
适用于运行于浏览器中的脚本应用,需要校验callback地址,而且只返回该应用注册的回调地址
APP直接请求token
GET /authorize?response_type=token&client_id=s6BhdRkqt3&
redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
Host: server.example.com
容器通过重定向返回token
HTTP/1.1 302 Found
Location: http://example.com/rd#access_token=FJQbwq9&
token_type=example&expires_in=3600
Resource Owner Password Credentials (基于用户名与密码模式)
称之为用户名密码模式,需要提供终端用户的用户名和密码,适用于比如操作系统或者高权限的应用。
APP直接带上用户名和密码请求
POST /token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=password&client_id=s6BhdRkqt3&
client_secret=47HDu8s&username=johndoe&password=A3ddj3w
容器直接返回token
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token":"SlAV32hkKG",
"token_type":"example",
"expires_in":3600,
"refresh_token":"8xLOxBtZp8",
"example_parameter":"example-value"
}
Client Credentials
基于APP的密钥直接进行授权,APP的权限非常大,慎用。这个模式可以考虑用于目前我们不需要弹出授权的特殊应用,如淘江湖,前端插件等。
APP直接根据客户端的密码来请求
POST /token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&client_id=s6BhdRkqt3&
client_secret=47HDu8s
容器直接返回token
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token":"SlAV32hkKG",
"token_type":"example",
"expires_in":3600,
"refresh_token":"8xLOxBtZp8",
"example_parameter":"example-value"
}
优先考虑实现的流程
Authorization Code为我们需要优先支持的流程,很多开源的OAUTH实现都是优先实现了该授权流程。ETAO的B2C网站会用这个流程与开放平台交互。
开源实现
目前OAUTH 2有比较多的开源实现,其中比较好的开源实现是OAuth for Spring Security,大家可以参考http://static.springsource.org/spring-security/oauth/tutorial.html这个网址去具体了解。有兴趣的同学可以去这个网址去下载其源代码看看http://maven.springframework.org/milestone/org/springframework/security/oauth/spring-security-oauth/1.0.0.M2/spring-security-oauth-1.0.0.M2-sources.jar ,容器主要关注下面几个类:org.springframework.security.oauth2.provider.OAuth2AuthorizationFilter
org.springframework.security.oauth2.provider. DefaultOAuth2GrantManager
org.springframework.security.oauth2.provider.verification.VerificationCodeFilter
第一个和第二个类为参数校验和参数解析,第三个类为响应生成的类。
TIP主要关注下面的类:
org.springframework.security.oauth2.provider.OAuth2ProtectedResourceFilter
这个类主要实现了对AccessToken的校验
- 大小: 51.5 KB
分享到:
相关推荐
yii2-oauth2-server, 用于实现OAuth2服务器的包装器( https yii2-oauth2-server用于实现OAuth2服务器的包装器( https://github.com/bshaffer/oauth2-server-php 插件)安装安装这里扩展的首选方法是通过 Composer 。...
springboot和apache的开源项目org.apache.oltu.oauth2组合搭建的oauth2环境,一般的oauth配置下就可以用了,但是我这个项目,是用原理上讲如何搭建oauth2,哪个controller转发到哪个controller,为什么这样,都有...
#OAuth2-Defender ##主要技术 Maven Spring Boot Spring Security Spring Security OAuth2.0 MySQL ##修改数据库配置 修改defender-oauth2-authorization\src\main\resources\...
赠送jar包:spring-security-oauth2-2.3.5.RELEASE.jar; 赠送原API文档:spring-security-oauth2-2.3.5.RELEASE-javadoc.jar; 赠送源代码:spring-security-oauth2-2.3.5.RELEASE-sources.jar; 赠送Maven依赖信息...
oauth2oauth2oauth2
模拟OAuth2 单点登录的java代码实现。模拟OAuth2 单点登录的java代码实现。模拟OAuth2 单点登录的java代码实现。模拟OAuth2 单点登录的java代码实现。
还在烦恼OAuth2技术只依赖boot吗?我提供了纯java技术实现OAuth2的全部实现,含客户端和服务端的完整解决方案。
使用spring oauth2框架做授权鉴定。想获取当前用户信息怎么办? 我们知道spring oauth2是基于spring security的实现的。 spring security可以通过SecurityContextHolder.getContext().getAuthentication()....
OAuth 2 0 is the next evolution of the OAuth protocol which was originally created in late 2006 OAuth 2 0 focuses on client developer simplicity while providing specific authorization flows for web a
spring security oauth2的源码,方便研究,备份一下。
2.授权服务 oauth,uaa 3.用户服务 system-service 4.其它微服务 others-service 授权流转方式 1.用户调用gateway的登陆接口 2.gateway里进行参数组织,调用oauth的颁发token接口 3.用户拿到token之后,带着token去...
OAuth2用户指南
描述了oauth2的原理(不含代码,如需demo请联系3546766954@qq.com),简单介绍了oauth2四种验证方式
包含 1.Getting Started with OAuth 2.0.pdf 2.Mastering OAuth 2.0.pdf 3.Oauth2 in Action.pdf 4.OAuth2.0 Cookbook.pdf
about sping secutity oauth2
springboot整合Oauth2,GateWay实现网关登录授权验证
Oauth2 Java demo
部署了一套非常全的OAuth2.0的例子 其中包括客户端和服务器端,专门为了OAuth2.0初学者提供了一个学习的资料 可以参考微博地址:http://blog.csdn.net/jbjwpzyl3611421/article/details/51130030
OAuth2 in Python.pdf
这段时间对Oauth2的学习,并将相关资料整理到一个文档中,方便大家统一查看。