Reputation: 19
I have a razor pages app [username and password auth] and a WebAPI app that uses JWT auth. Both the services use the same user table. After user proceeds to checkout on the Razor pages app, I need to call an API in the WebAPI that that requires JWT. How can I generate this token for a logged in user in my razor pages app ?
Upvotes: 1
Views: 843
Reputation: 21883
Ali.Ahmadi's comment is useful, I also create a sample project and it works for me. I can use username and password to login, and get the jwt token. You can follow this article and use it in your razor pages app.
Add a link to github to prevent links in comments from breaking.
Then in your webapi project, you can create a JWTMiddleware to valid this token.
For more details, you can check the blogs, it contains detailed description.
Create And Validate JWT Token In .NET 5.0
Upvotes: 1