当前位置:网站首页>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 .
边栏推荐
- QT常见概念-1
- Cloud Mail . NET Edition
- Metaforce force meta universe fossage 2.0 smart contract system development (source code deployment)
- 巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
- Unity uses maskablegraphic to draw a line with an arrow
- Digital scrolling increases effect
- widerperson数据集转化为YOLO格式
- The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
- 记一次JAP查询导致OOM的问题分析
- MySQL提升大量数据查询效率的优化神器
猜你喜欢
Classify the features of pictures with full connection +softmax
Redis入门完整教程:复制拓扑
The panel floating with the mouse in unity can adapt to the size of text content
Number theory --- fast power, fast power inverse element
Form validation of uniapp
6-6 vulnerability exploitation SSH security defense
How-PIL-to-Tensor
数字滚动增加效果
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
Have fun | latest progress of "spacecraft program" activities
随机推荐
服装企业部署MES管理系统的五个原因
Metaforce force meta universe fossage 2.0 smart contract system development (source code deployment)
wireshark安装
6-6 vulnerability exploitation SSH security defense
Apifox, is your API interface document rolled up like this?
换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
Redis入门完整教程:复制原理
uniapp适配问题
Oauth2协议中如何对accessToken进行校验
c语言字符串排序
Huitong programming introductory course - 2A breakthrough
Wireshark installation
Redis getting started complete tutorial: replication topology
Es6中Promise的使用
Babbitt | metauniverse daily must read: is IP authorization the way to break the circle of NFT? What are the difficulties? How should holder choose the cooperation platform
Code debugging core step memory
Introduction to ins/gps integrated navigation type
LeetCode 77:组合
商城商品的知识图谱构建
记一次JAP查询导致OOM的问题分析