I'm basically creating a login feature and i want to create jwt token on server side in order to post response the jwt token to frontend as requested with email and password. In payload i want to include only a specific id which is already exist in database.How can I create jwt in a simple Way in Java
Asked
Active
Viewed 1,420 times
0
-
Possible duplicate of [JWT (JSON Web Token) library for Java](https://stackoverflow.com/questions/23808460/jwt-json-web-token-library-for-java) – Jul 26 '19 at 14:27
-
on https://jwt.io/#libraries-io you can find a lot of libs, and usually you get examples for their usage in the docs or homepage. – jps Jul 26 '19 at 14:30
1 Answers
3
You can create it for example with Java JWT: JSON Web Token for Java and Android
Example:
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import java.security.Key;
// We need a signing key, so we'll create one just for this example. Usually
// the key would be read from your application configuration instead.
Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
String jws = Jwts.builder().setSubject("Joe").signWith(key).compact();

Janko Muzykant
- 31
- 2