当前位置:网站首页>. net webapi access authorization mechanism and process design (header token + redis)
. net webapi access authorization mechanism and process design (header token + redis)
2022-04-23 03:18:00 【Pingshan CP3】
background :
1. Need to be in .net5 WebAPI Add access authorization mechanism to , That is, issue user credentials when logging in , Later, you need to access other interfaces through credentials , If the voucher is illegal , The interface cannot be accessed normally ;
2. Website embedded into winform The client , utilize winform You can get the client's mac Permission to address , take mac Address as part of permission , the mac Address and account are bound to realize that the account can only be used on the specified client computer ;
3. In order to prevent getting token Then use it on other clients , utilize IP binding token;
Realization :
First, after successful login , Client side IP As encryption key,username( Login account )+guid+cpu The serial number encrypts the encrypted content , The encryption result is used as token The certificate is issued to the user ;
follow-up Api Access authorization filtering process :
1. Formal environment , First limit the source of the request , Such as http request header Medium referer, Check whether it is in the white list set by the system ; If not , Access denied ;
2. secondly , stay header To take token, If you can't get it , Access denied ;
3. Get the client IP, take IP Process as length 32 String ( Now it's time to get rid of non numbers , On the right 0 fill );
4. take 32 Bit string as key Symmetric decryption token, If decryption fails, access is denied ;
5. Decrypted string , The content format is :username + "|" + guid+"|"+cpuid;guid As Redis Of key DE value , Can't get , Access denied ;
6. from Redis Out of Value, The content format is :username+"|"+keeplogin+"|"+cpuid;cpuid Is the name of the client where the account is logged in cpu Serial number
7. use "_hw_" + username As key Go to Redis To take Value, If empty, access denied ;
8. 7 Taken in Value Bound for restricted account cpu Serial number , by ”all” Time means no limit , It can be accessed by the client at will ; Not for “all” when , Judge 7 in Value Does it include 6 in cpuid, If not included , Access denied ;
Visit the flowchart :
Be careful : The encryption method and content can be done according to the specific business restrictions , Here is just a list of boarding in winform Website in API Access authorization process ;
版权声明
本文为[Pingshan CP3]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220627116921.html
边栏推荐
- MySql分组查询规则
- Node configuration environment CMD does not take effect
- 2022g2 boiler stoker examination question bank and online simulation examination
- socket編程 send()與 recv()函數詳解
- 12. < tag linked list and common test site synthesis > - lt.234 palindrome linked list
- Idempotency practice operation, explaining idempotency based on business
- 研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
- [untitled]
- 可以接收多种数据类型参数——可变参数
- Configuration table and page information automatically generate curd operation page
猜你喜欢
Configure automatic implementation of curd projects
Experiment 5 components and event handling
C WPF UI framework mahapps switching theme
Charles uses three ways to modify requests and responses
《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
2022年度Top9的任务管理系统
Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
[MySQL] left Function | Right Function
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
Knowledge of software testing~
随机推荐
Aspnetcore configuration multi environment log4net configuration file
批量下载文件----压缩后再下载
MySQL installation pit
Find the number of leaf nodes of binary tree
Cefsharp stores cookies and reads cookies
你真的懂hashCode和equals吗???
C语言实现通讯录----(静态版本)
数据挖掘系列(3)_Excel的数据挖掘插件_估计分析
Peut recevoir plusieurs paramètres de type de données - paramètres variables
ThreadLocal 测试多线程变量实例
New ORM framework -- Introduction to beetlsql
OLED multi-level menu record
二进制文件版本控制工具选择难?看完这篇你会找到答案
全新的ORM框架——BeetlSQL介绍
Swap the left and right of each node in a binary tree
Fundamentals of software testing and development
2022年做跨境电商五大技巧小分享
Is it difficult to choose binary version control tools? After reading this article, you will find the answer
Super easy to use [general excel import function]
OLED多级菜单记录