Advertisement
Guest User

JWT

a guest
Mar 20th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. TimeZone tz = TimeZone.getTimeZone("UTC");
  2. DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
  3. df.setTimeZone(tz);
  4. String nowAsISO = df.format(new Date());
  5.  
  6. HashMap<String, String> keyValues = new HashMap<String, String>();
  7. keyValues.put("consumerKey", this.annotatorKey);
  8. keyValues.put("userId", this.userId);
  9. keyValues.put("issuedAt", nowAsISO);
  10. keyValues.put("ttl", "60000");
  11.  
  12. JWTUtils jwtutil = new JWTUtils(this.userId, this.annotatorKey, this.annotatorSecret);
  13. String signedToken = "";
  14. try {
  15.     JsonToken token = jwtutil.createToken(keyValues);
  16.     signedToken = token.serializeAndSign();
  17. } catch (InvalidKeyException e) {
  18.     e.printStackTrace();
  19. } catch (SignatureException e) {
  20.     e.printStackTrace();
  21. }
  22.  
  23. resp.setContentType("text/plain");
  24. PrintWriter out = resp.getWriter();
  25. out.println(signedToken);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement