Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public JWTUtils(String issuer, String key, String secret) {
- this.ISSUER = issuer;
- this.CONSUMER_KEY = key;
- this.CONSUMER_SECRET = secret;
- }
- public JsonToken createToken(HashMap<String, String> keyValues) throws InvalidKeyException, SignatureException {
- JsonToken token;
- //Current time and signing algorithm
- Calendar cal = Calendar.getInstance();
- HmacSHA256Signer signer = new HmacSHA256Signer(ISSUER, CONSUMER_KEY, CONSUMER_SECRET.getBytes());
- //Configure JSON token
- token = new JsonToken(signer);
- token.setIssuedAt(new Instant(cal.getTimeInMillis()));
- token.setExpiration(new Instant(cal.getTimeInMillis() + 86400L)); // one day
- //Configure request object, which provides information of the item
- JsonObject payload = token.getPayloadAsJsonObject();
- for (String key : keyValues.keySet()) {
- payload.addProperty(key, keyValues.get(key));
- }
- return token;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement