简体   繁体   English

JWT 和 ASP.NET Core MVC 应用程序

[英]JWT with ASP.NET Core MVC application

I created a service我创建了一个服务

I have implemented my method that will generate a token我已经实现了生成令牌的方法

At my Action Login I don't know how to ensure the comsommation of the generated token on everything I use (Razor, HTML)在我的操作登录中,我不知道如何确保生成的令牌与我使用的所有内容(Razor、HTML)相匹配

I would like to set up an Authentication using JWT token with an ASP.NET Core MVC application.我想使用 JWT 令牌和 ASP.NET Core MVC 应用程序设置身份验证。

This is the first time using a token, all the articles and tutorials that I had to consult use JWT with the Web API which is not my case, because my project is of type MVC.这是第一次使用令牌,我必须参考的所有文章和教程都使用 JWT 和 Web API 这不是我的情况,因为我的项目是 MVC 类型的。

Can someone help me or orient me?有人可以帮助我或指导我吗?

I think what you are trying to do is Authenticate the user by JWT which is not possible.我认为您要做的是通过JWT对用户进行身份验证,这是不可能的。 You'll have to generate JWT after the user has logged in with a username and password.用户使用用户名和密码登录后,您必须生成JWT

Return this token as a response to the user so the user can use the token for other API requests.将此令牌作为对用户的响应返回,以便用户可以将令牌用于其他 API 请求。

For validation refere this. 验证参考这个。

When should you use JSON Web Tokens?什么时候应该使用 JSON Web 代币?

Authorization : This is the most common scenario for using JWT. Once the user is logged in, each subsequent request will include the JWT, allowing the user to access routes, services, and resources that are permitted with that token.授权:这是使用 JWT 最常见的场景。用户登录后,每个后续请求都将包含 JWT,允许用户访问该令牌允许的路由、服务和资源。 Single Sign On is a feature that widely uses JWT nowadays, because of its small overhead and its ability to be easily used across different domains. JWT 是当今广泛使用的一项功能,因为它的开销很小并且能够轻松跨不同域使用。

Information Exchange : JSON Web Tokens are a good way of securely transmitting information between parties.信息交换:JSON Web 令牌是在各方之间安全传输信息的好方法。 Because JWTs can be signed—for example, using public/private key pairs—you can be sure the senders are who they say they are.因为 JWT 可以签名——例如,使用公钥/私钥对——你可以确定发送者是他们所说的人。 Additionally, as the signature is calculated using the header and the payload, you can also verify that the content hasn't been tampered with.此外,由于签名是使用 header 和有效负载计算的,您还可以验证内容是否未被篡改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM