. Net core jwt entry record, corejwt
I searched a lot of jwt articles from Baidu search and wrote a demo with the article. Here I will record the problems encountered during the learning process. If you read the article multiple times, it is better to manually implement it once.
The template has been uploaded to github.com: dogvane/webapi_effect_template
Let the project fly first
Only Articles and code snippets are available on the Internet. The articles and code snippets found in github are either unable to run (other Dependencies to be configured, databases, and so on), or the code structure is extremely complicated and I don't know where to change them.
For the demo, only two functions are required.
1. Generate the jwt token and return it to the front-end (AccountController. Login)
2. Execute a business method that requires permission and obtain the user ID (AccountController. DoYourTask) in it)
Note:
Generate the token code, if the issuer information and startup. inconsistency in cs cannot be verified, especially when your code is copied from two places (do not ask me how to know o (> unknown <) o ).
Therefore, a website that parses jwt information is very important online parsing jwt parameter http://jwt.calebb.net/
During the test, swagger is used to enable the swagger ui request to carry header information.Https://www.cnblogs.com/JacZhu/p/6188968.html
You can understand why UserId should be parsed in BaseController. I have found many articles at the beginning. None of them refer to how to parse data from jwt. It has been a long time since my mind has not been transferred.
In fact, you can find out from another angle. You don't need to find any articles. token can be obtained from the Request. The jwt processing class has been added to the system. You just need to check the api. Therefore, it is better to read a hundred articles.
Add several keywords to facilitate the search:. net core jwt Decode userid