当前位置:网站首页>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 .
边栏推荐
- A complete tutorial for getting started with redis: AOF persistence
- Unity使用MaskableGraphic画一条带箭头的线
- MMDetection3D加载毫米波雷达数据
- Error in fasterxml tostringserializerbase
- 知识图谱构建全流程
- Django database (SQLite) basic introductory tutorial
- CDB PDB user rights management
- Es6中Promise的使用
- 新标杆!智慧化社会治理
- How to design interface test cases? Teach you a few tips to draft easily
猜你喜欢
[secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]
LeetCode 77:组合
Redis introduction complete tutorial: client case analysis
导数、偏导数、方向导数
【Socket】①Socket技术概述
数论 --- 快速幂、快速幂求逆元
Redis Getting started tutoriel complet: positionnement et optimisation des problèmes
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?
dotConnect for DB2数据提供者
wireshark安装
随机推荐
Redis入门完整教程:复制拓扑
Static proxy of proxy mode
Left path cloud recursion + dynamic planning
用全连接+softmax对图片的feature进行分类
PSINS中19维组合导航模块sinsgps详解(时间同步部分)
简单冒泡排序
Oauth2协议中如何对accessToken进行校验
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (initial assignment part)
MySQL is an optimization artifact to improve the efficiency of massive data query
一文读懂Faster RCNN
NuScenes数据集关于Radar数据的统计
测试优惠券要怎么写测试用例?
Code debugging core step memory
Number theory --- fast power, fast power inverse element
Safety delivery engineer
知识图谱构建全流程
Redis getting started complete tutorial: replication configuration
Redis getting started complete tutorial: common exceptions on the client
Cglib agent in agent mode