Advertisement
Guest User

JWTUtils

a guest
Mar 20th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. public JWTUtils(String issuer, String key, String secret) {
  2.     this.ISSUER = issuer;
  3.     this.CONSUMER_KEY = key;
  4.     this.CONSUMER_SECRET = secret;
  5. }
  6.  
  7. public JsonToken createToken(HashMap<String, String> keyValues) throws InvalidKeyException, SignatureException {
  8.     JsonToken token;
  9.    
  10.     //Current time and signing algorithm
  11.     Calendar cal = Calendar.getInstance();
  12.     HmacSHA256Signer signer = new HmacSHA256Signer(ISSUER, CONSUMER_KEY, CONSUMER_SECRET.getBytes());
  13.  
  14.     //Configure JSON token
  15.     token = new JsonToken(signer);
  16.     token.setIssuedAt(new Instant(cal.getTimeInMillis()));
  17.     token.setExpiration(new Instant(cal.getTimeInMillis() + 86400L)); // one day
  18.    
  19.     //Configure request object, which provides information of the item
  20.     JsonObject payload = token.getPayloadAsJsonObject();
  21.     for (String key : keyValues.keySet()) {
  22.         payload.addProperty(key, keyValues.get(key));
  23.     }
  24.  
  25.     return token;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement