当前位置:网站首页>Get started with the OAuth protocol easily with a case
Get started with the OAuth protocol easily with a case
2022-08-10 05:13:00 【Xiaoyu love of programming】
Easy Getting Started with OAuth Protocol with a Case
OAuth (Open Authorization) is an open web standard for authorization that allows users to authorize third-party applications to access information they store on another service provider without providing a username and password to the third partyMobile apps or share everything about their data.OAuth is widely used all over the world and the current version is version 2.0.
Background
There is a program called "Credit Card Manager" (www.a.com), which can automatically read emails related to credit cards from NetEase cloud mailboxes, and then analyze and summarize them to form a report.
Password
How does "Credit Card Manager" access NetEase Cloud Mailbox?
- The user directly enters the account number and password, and then "Credit Card Manager" reads the content of the NetEase cloud mailbox
Problems arise?
- There is a trust problem: if you are just a small website, users will not dare to give you such important account and password information.
token
How does "Credit Card Manager" access NetEase Cloud Mailbox?(See the overall process below)
- The login interface provides a new entry, use the NetEase account to log in.After clicking, it will jump to NetEase's authentication system to log in, and then Netease's authentication system requires you to enter your username and password, and asks you whether to run "Credit Card Manager" to access your mailbox.
- After confirming, redirect to the "Credit Card Manager" website, and bring a token, you can access NetEase mailbox through API.
- Username and password will not be involved in the whole process.The token is issued by the NetEase Certification Center, which actually represents the user's authorization for the credit card manager to access the mailbox, so with this token, you can access your mailbox
Overall process
How does NetEase trust the "Credit Card Manager"?
- You need to register the "Credit Card Manager" on NetEase, and NetEase will send a app_id and app_secret to the "Credit Card Manager".Redirect to NetEase, you need to send these things, so NetEase knows that the "Credit Card Manager" application is applying for authorization
How to store this token?
The browser saves the token
By means of hash fragment, bring this token parameter when requesting for example: www.a.com/callback#token=
”
Why is it stored on the client side?
- In order to improve security: it will only stay on the browser side, only Javascript can access it, and it will not be sent to other servers through http request again
Questions?In step 6 on the figure, there will be security problems when the token is transmitted in the form of name text, which can be obtained through the browser's history record or access log.
authorization code + token
How to hide the token?
Introduces an intermediate layer called Authorization Code.When the user logs in with the NetEase account, the NetEase Authentication Center will not directly send a token to the "Credit Card Manager" this time, but will send an authorization code,
After the Credit Card Manager server gets this code, it will visit the NetEase Authentication Center again in the background, and this time the NetEase Authentication Center will issue the real token to the "Credit Card Manager".
Why is it designed this way?
- Through the returned authorization code, the token application process is 'secretly' completed in the server background, so the token browser can't touch it at all
The code is also transmitted in clear text, so there is no security problem code?
- The authorization code is associated with the app_id and app_secret applied by the credit card manager, only the token request issued by the credit card manager will be considered legitimate by the NetEase Authentication Center; the authorization code can also be limited in time, such as 5 minutes invalid, and the authorization code can only be changed to the token once, and the second time will not work
Summary
What this article is about is actually the three authentication methods in OAuth, in order:
- Resource Owner Password Credentials Grant
- Implicit Grant
- Authorization Code Grant
There is another called Client credentials, which is used less and is not covered in this article.
In OAuth, there are several terms you can understand:
- Resource owner: the user above
- Resource Server: NetEase Mailbox
- Client: the credit card manager above
- Authorization Server: The NetEase Authentication Center above
References:
"Code Farmer Turning Over"
边栏推荐
猜你喜欢
深度梳理:防止模型过拟合的方法汇总
文献 | 关于心理活动符号学,你知道多少?
Flutter开发:报错The following assertion was thrown resolving an image codec:Unable to…的解决方法
基于BP神经网络的多因素房屋价格预测matlab仿真
线程(下):读写者模型\环形队列\线程池
OAuth2的使用场景、常见误区、使用案例
Depth of carding: prevent model fitting method
如何模拟后台API调用场景,很细!
二进制中负数为何要用补码形式来表示——二进制加减法
【LeetCode】41、 缺失的第一个正数
随机推荐
咨询cdc 2.0 for mysql不执行flush with read lock.怎么保证bin
FPGA工程师面试试题集锦31~40
pytorch learning
线程(下):读写者模型\环形队列\线程池
summer preschool assignments
重要转型升级
单页面应用
leetcode每天5题-Day13
看了几十篇轻量化目标检测论文扫盲做的摘抄笔记
Flutter开发:报错The following assertion was thrown resolving an image codec:Unable to…的解决方法
在vscode中屏蔽Alt热键
接口调试还能这么玩?
Introduction to curl command
FPGA engineer interview questions collection 11~20
How does flinksql write that the value of redis has only the last field?
添加路由的2种方式--router
MySQL simple tutorial
应用在智能触摸遥控器中的触摸芯片
深度学习之-01
各位大佬,idea中测试使用FlinkCDC SQL 读取Mysql 数据写入Kafka中,代码中创