RFC6749 Oauth2.0 阅读笔记

栏目: 后端 · 前端 · 发布时间: 4年前

内容简介:最近有facebook好友的接入工作,重读了一遍oauth2.0。相较第一次读,对四种授权模式,主要是Authorization Code, Implicit Grant有了正确的理解。所以有了这篇。关键是,OAuth 引入了一个授权层,用来分离两种不同的角色:客户端和资源所有者。从而资源所有者(用户)的credentials,主要是密码,不会暴露给客户端。

为啥要写这篇

最近有facebook好友的接入工作,重读了一遍oauth2.0。相较第一次读,对四种授权模式,主要是Authorization Code, Implicit Grant有了正确的理解。所以有了这篇。

1. 为什么需要Oauth2

https://tools.ietf.org/html/r...

OAuth addresses these issues by introducing an authorization layer
   and separating the role of the client from that of the resource
   owner.  In OAuth, the client requests access to resources controlled
   by the resource owner and hosted by the resource server, and is
   issued a different set of credentials than those of the resource
   owner.

关键是,OAuth 引入了一个授权层,用来分离两种不同的角色:客户端和资源所有者。从而资源所有者(用户)的credentials,主要是密码,不会暴露给客户端。

2. four roles

https://tools.ietf.org/html/r...

resource owner

An entity capable of granting access to a protected resource. When the resource owner is a person, it is referred to as an end-user.

资源拥有者, 如豆瓣用户,假设认证服务器是微信。

resource server

The server hosting the protected resources, capable of accepting and responding to protected resource requests using access tokens.

用户访问的网站,如豆瓣。

client

An application making protected resource requests on behalf of the resource owner and with its authorization. The term "client" does not imply any particular implementation characteristics (e.g., whether the application executes on a server, a desktop, or other devices).

客户端,是一个程序,代表资源拥有者的用其授权发起资源访问,可以在桌面上的浏览器,手机端的app,服务器上运行。

authorization server

The server issuing access tokens to the client after successfully authenticating the resource owner and obtaining authorization.

在认证,授权成功后,发放访问token至客户端, 如微信发放访问token至豆瓣。

RFC6749 Oauth2.0 阅读笔记

3. client

todo 结合facebook开发者文档,结合具体参数,分析为什么要这么做。

4. four grant types

https://tools.ietf.org/html/r...

四种获得授权的方式,即client如何拿到access token.

An authorization grant is a credential representing the resource
   owner's authorization (to access its protected resources) used by the
   client to obtain an access token. This specification defines four
   grant types -- authorization code, implicit, resource owner password
   credentials, and client credentials -- as well as an extensibility
   mechanism for defining additional types.

Authorization Code

https://tools.ietf.org/html/r...

关键在于authorization code只可使用一次,假设resource owner到client的链接为http,可能被窃听。

因为到authorization server的链接是https, access_token绝不会被暴露,而授权码就算被暴露,也会因用户的充登,而让此前中间人获取的access_token失效。

RFC6749 Oauth2.0 阅读笔记

Implicit Grant

https://tools.ietf.org/html/r...

相较Authorization Code,authorization server直接返回access token, 关键点在于access token在callback中,以fragment方式返回access token,这样,user-agent访问Web-Hosted Client Resource时,不会带上access token,access token留在本地,注意这种情况下client也在本地。

Resource Owner Password Credentials Grant

https://tools.ietf.org/html/r...

用户相当信任client,直接给密码client,client用密码获得access token.

Client Credentials Grant

https://tools.ietf.org/html/r...

authorization server完全相信client,client通过证书直接拿access token

参考


以上所述就是小编给大家介绍的《RFC6749 Oauth2.0 阅读笔记》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

JavaScript高级程序设计:第2版

JavaScript高级程序设计:第2版

Nicholas Zakas / 李松峰、曹力 / 人民邮电出版社 / 2010-7 / 89.00元

《JavaScript高级程序设计(第2版)》在上一版基础上进行了大幅度更新和修订,融入了近几年来JavaScript应用发展的最新成果,几乎涵盖了所有需要理解的重要概念和最新的JavaScript应用成果。从颇具深度的JavaScript语言基础到作用域(链),从引用类型到面向对象编程,从极其灵活的匿名函数到闭包的内部机制,从浏览器对象模型(BOM)、文档对象模型(DOM)到基于事件的Web脚本......一起来看看 《JavaScript高级程序设计:第2版》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

SHA 加密
SHA 加密

SHA 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具