当前位置:网站首页>OAuth 2.0一键登录那些事
OAuth 2.0一键登录那些事
2022-06-25 06:39:00 【爱叨叨的程序狗】
OAuth 2.0应用场景
程序员对Gitee和Github都不陌生,Github可能是起源时间最早、用户范围最大的代码开源仓库,Gitee作为国产代码仓库的后起之秀,在用户模块也是做到了兼容Github的功能,如,在Gitee的登录界面可以通过Github授权的方式登录。这就是今天我要讲的OAuth 2.0,大家可以去Gitee体验一下UI交互流程,以更形象的理解OAuth 2.0的授权流程。


OAuth2.0业务角色

作用:
使客户端安全可控的获取”用户“授权,与服务提供商交互。
OAuth 2.0运行流程
摘自RFC 6749.

用户授权方式有五种:
- 授权码模式(authorization code)
- 简化模式(implicit)
- 密码模式(resource owner password credentials)
- 客户端模式(client credentials)
授权方式-以authorization-code为例

认证流程:
- 用户访问客户端,客户端跳转至认证服务器认证页面
- 用户选择是否授权
- 若选择授权,则用户自行选择认证登录,如:验证码、账号密码等
- 认证服务器发放Authorization Code,页面从认证服务器Redirection URI到Client
- Client拿Authorization Code去请求认证服务器
- 若认证无误,则发放Access Token/Refresh Token
信息补充
Access Token: An OAuth Access Token is a string that the OAuth client uses to make requests to the resource server.
Refresh Token: An OAuth Refresh Token is a string that the OAuth client can use to get a new access token without the user’s interaction.
Scope: Scope is a mechanism in OAuth 2.0 to limit an application’s access to a user’s account. An application can request one or more scopes, this information is then presented to the user in the consent screen, and the access token issued to the application will be limited to the scopes granted.
更为形象的流程-来自阿里云
SP:客户端
IDP:认证服务器
A步骤中,客户端申请认证的URI,包含以下参数:
- response_type:表示授权类型,必选项,此处的值固定为"code"
- client_id:表示客户端的ID,必选项
- redirect_uri:表示重定向URI,可选项。认证服务器认证完成后,重定向到客户端的uri
- scope:表示申请的权限范围,可选项
- state:表示客户端的当前状态,可以指定任意值,认证服务器会原封不动地返回这个值。
如:
http://example.com?code=xxx&state=test&response_type=code&client_id=xxxx&redirect_uri=xxxx.com
C步骤中,服务器回应客户端的URI,包含以下参数:
- code:表示授权码,必选项。该码的有效期应该很短,通常设为10分钟,客户端只能使用该码一次,否则会被授权服务器拒绝。该码与客户端ID和重定向URI,是一一对应关系。
- state:如果客户端的请求中包含这个参数,认证服务器的回应也必须一模一样包含这个参数。
D步骤中,客户端申请服务端令牌,入参有:
返回值有:
认证流程完成,接下来就可以拿服务端生成的Access Token获取服务端的资源了。
更新token
Access Token 一般都设有过期时间,在访问时如果客户端的访问令牌已经过期,则需要使用”更新令牌“申请一个新的访问令牌。入参使用grantType、refreshToken、scope。
边栏推荐
- VectorDraw Developer Framework 10.10
- Static bit rate (CBR) and dynamic bit rate (VBR)
- 稳压二极管的原理,它有什么作用?
- 鸿蒙页面菜单的选择
- [batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)
- Alphassl wildcard certificate for one month
- My debut is finished!
- Cocos learning diary 3 - API acquisition nodes and components
- [introduction to UVM== > episode_9] ~ register model, integration of register model, general methods of register model, application scenarios of register model
- CGLIB动态代理
猜你喜欢

用动图讲解分布式 Raft

【蒸馏】PointDistiller: Structured Knowledge DistillationTowards Efficient and Compact 3D Detection

Genuine photoshop2022 purchase experience sharing
![[leetcode] two num · sum of two numbers](/img/9e/79c9deae9f853a265b5b536998b655.png)
[leetcode] two num · sum of two numbers

5g private network market is in full swing, and it is crucial to solve deployment difficulties in 2022

Vscode official configuration synchronization scheme

Tupu software digital twin 3D wind farm, offshore wind power of smart wind power

【批处理DOS-CMD命令-汇总和小结】-文件与目录操作命令(md、rd、xcopy、dir、cd、set、move、copy、del、type、sort)

Leetcode daily question - 515 Find the maximum value in each tree row

用太极拳讲分布式理论,真舒服!
随机推荐
VectorDraw Web Library 10.10
[batch dos-cmd command - summary and summary] - application startup and call, service and process operation commands (start, call, and)
Authentique Photoshop 2022 expérience d'achat partage
Tempest HDMI leak receive 2
[batch dos-cmd command - summary and summary] - commands related to Internet access and network communication (Ping, Telnet, NSLOOKUP, ARP, tracert, ipconfig)
Enter an integer with any number of bits, and output the sum of each bit of the number. For example: 1234 – > 10
RTKLIB-b33版本中GALILEO广播星历存储问题
指南针可以开股票账户吗?安全吗?
Domestic MCU perfectly replaces STM chip model of Italy France
韩信大招:一致性哈希
Chang Wei (variables and constants) is easy to understand
College entrance examination voluntary filling, why is the major the last consideration?
【pytest】修改allure报告中的logo及参数化
Explain distributed raft with dynamic diagram
高考志愿填报,为啥专业最后考虑?
[leetcode] two num · sum of two numbers
Vscode official configuration synchronization scheme
高数基础_函数的奇偶性
Harmony美食菜单界面
【Qt】快捷键


