用于 Java 的 JWT(JSON Web 令牌)库 [英] JWT (JSON Web Token) library for Java

查看:30
本文介绍了用于 Java 的 JWT(JSON Web 令牌)库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 Java 和 AngularJS 开发的 Web 应用程序,并选择实现令牌身份验证和授权.出于练习的目的,我已经将凭据发送到服务器,生成一个随机令牌存储它并将其发送回客户端.在对服务器的每个请求中,我都会在标头中附加令牌,并且它运行良好.对于身份验证的观点是完美的,不需要更多.

I am working on a web application developed using Java and AngularJS and chose to implement token authentication and authorization. For the exercise purpose, I've come to the point where I send the credentials to the server, generate a random token store it and send it back to the client. At every request to the server I'm attaching the token in the header and it works perfectly. For the authentication point of view is perfect and wouldn't need more.

但是,我现在想跟踪用户类型(管理员、普通用户...),以及它的 id 或任何其他唯一字段;据我了解,我必须在登录操作期间发送回客户端的令牌中对其进行加密.对吗?

However, I now want to keep track of the user type (admin, regular user...), as well as it's id, or any other unique field; as I understood I have to encrypt that in the token that I'm sending back to the client during the log in action. Is that correct?

是否有任何您使用过的 JWT 库可以生成、加密和解密此类令牌?非常感谢指向库的 API 和 Maven 依赖项的链接.

Is there any JWT library that you used and can generate, encrypt and decrypt such tokens? A link to the library's API and Maven dependency would be much appreciated.

谢谢

推荐答案

如果有人需要答案,

我使用了这个库:http://connect2id.com/products/nimbus-jose-jwtMaven 在这里:http://mvnrepository.com/artifact/com.nimbusds/nimbus-jose-jwt/2.10.1

I used this library: http://connect2id.com/products/nimbus-jose-jwt Maven here: http://mvnrepository.com/artifact/com.nimbusds/nimbus-jose-jwt/2.10.1

这篇关于用于 Java 的 JWT(JSON Web 令牌)库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆