当前位置:网站首页>How to verify accesstoken in oauth2 protocol
How to verify accesstoken in oauth2 protocol
2022-07-07 03:00:00 【Misty jam】
Hello everyone , I am ethereal . Let's talk today oauth2.0 Of accesstoken Check logic .
summary
This article is from golfers Never Sett* The question of

Finish this problem , I feel that readers are interested in accesstoken The verification logic of is not clear , So I specially wrote this article to explain .

First we need to know Oauth2 It's a licensing agreement , Before the client accesses a protected resource , You need to get through the authentication server first accesstoken, Then by putting accesstoken Access resource server .
secondly ,Oauth2 There are two kinds of tokens issued by the authentication server : Opaque token (opaque tokens) and Transparent token (not opaque tokens) To put it bluntly, it is uuid and jwt The difference between .
Okay , Now comes the question , On the client side accesstoken Access resource server , How does the resource server know about you accesstoken It's legal ?
When you get the token is uuid when , The resource server cannot judge the validity of your token by itself .
At this time, there are generally two kinds of verification logic :
Remote verification
The authorization server exposes an endpoint , For valid tokens , It returns the permissions previously granted by the user who issued the token , This port is called check_token Endpoint ( In many places, it is also called token introspection endpoint ). We can Directly use the default interface provided by the authentication server /oauth/check_toen You can also customize an interface .
The resource server calls for each request check_token Endpoint , such , It will validate the token received from the client , And get the permission granted to the client . The resource server can be accessed through yaml Middle configuration security.oauth2.resource.user-info-uri Specify the authentication server check_token Endpoint address .
Blackboard mode
Resource servers and authorization servers use shared storage , Common ones are database and redis.
Authorization server generates accesstoken Then it will be persisted and stored , In this way, the resource server can also verify by accessing this shared storage accesstoken The effectiveness of the .
JWT
If the authentication server issues you jwt, At this time, the client will bring jwt Access resource server , The resource server can resolve the token directly , No need to call the authentication server . But you need to pay attention to the use of jwt Be sure to configure the key , Asymmetric keys are recommended for production environments .
Summary
oauth2 in accesstoken The verification logic is basically the above three
Call the authorization server directly
Use shared database ( Blackboard mode )
Use it directly JWT, Resource server self verification
Now in actual development, it is used in most cases jwt, This can reduce the interactive requests between the resource server and the authentication server , Improve access efficiency .
Of course , If you are right about oauth2 The agreement is not well understood , I recommend you to watch a short video I recorded before , It has a detailed description of .
边栏推荐
- The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
- Number theory --- fast power, fast power inverse element
- MySQL提升大量数据查询效率的优化神器
- Derivative, partial derivative, directional derivative
- Redis入门完整教程:复制拓扑
- Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
- fasterxml ToStringSerializerBase报错
- A complete tutorial for getting started with redis: problem location and optimization
- The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
- 数字滚动增加效果
猜你喜欢

导数、偏导数、方向导数

如何设计好接口测试用例?教你几个小技巧,轻松稿定

Planning and design of double click hot standby layer 2 network based on ENSP firewall

Electrical engineering and automation

How to write test cases for test coupons?

左程云 递归+动态规划

Redis入门完整教程:复制拓扑

Es6中Promise的使用
![[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication](/img/09/b9d50f7a10e6898ac4088ee005d00b.png)
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication

Oauth2协议中如何对accessToken进行校验
随机推荐
wzoi 1~200
Remember the problem analysis of oom caused by a Jap query
c语言(字符串)如何把字符串中某个指定的字符删除?
wzoi 1~200
电气工程及其自动化
Redis getting started complete tutorial: common exceptions on the client
Redis入門完整教程:問題定比特與優化
Mmdetection3d loads millimeter wave radar data
商城商品的知识图谱构建
Analysis of USB network card sending and receiving data
MySQL
widerperson数据集转化为YOLO格式
Install redis from zero
记一次JAP查询导致OOM的问题分析
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
Unity使用MaskableGraphic画一条带箭头的线
【软件测试】最全面试问题和回答,全文背熟不拿下offer算我输
Statistics of radar data in nuscenes data set
Dotconnect for DB2 Data Provider
你不可不知道的Selenium 8种元素定位方法,简单且实用