-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
26 lines (21 loc) · 788 Bytes
/
App.java
File metadata and controls
26 lines (21 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package org.ankur.jwt;
import java.io.UnsupportedEncodingException;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
/**
* Hello world!
*
*/
public class App {
public static void main(String[] args) throws UnsupportedEncodingException {
String jwt = Jwts.builder().setSubject("users/TzMUocMF4p").claim("name", "Robert Token Man")
.claim("scope", "self groups/admins").signWith(SignatureAlgorithm.HS256, "secret".getBytes("UTF-8"))
.compact();
System.out.println(jwt);
Jws<Claims> claims = Jwts.parser().setSigningKey("secret".getBytes("UTF-8")).parseClaimsJws(jwt);
String scope = (String) claims.getBody().get("scope");
System.out.println(scope);
}
}