Created
March 18, 2016 07:55
-
-
Save abhirockzz/9fb2194ccd1b03ed0b42 to your computer and use it in GitHub Desktop.
Creating a JWT (using the jose4j library - https://bitbucket.org/b_c/jose4j/wiki/Home)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//exception handling excluded to avoid verbosity | |
RsaJsonWebKey rsaJsonWebKey = RsaKeyProducer.produce(); | |
JwtClaims claims = new JwtClaims(); | |
claims.setSubject("user1"); | |
JsonWebSignature jws = new JsonWebSignature(); | |
jws.setPayload(claims.toJson()); | |
jws.setKey(rsaJsonWebKey.getPrivateKey()); | |
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256); | |
String jwt = jws.getCompactSerialization(); | |
//the encoded JWT | |
eyJhbGciOiJSUzI1NiJ9 | |
.eyJzdWIiOiJ1c2VyMSJ9 | |
.HG9GCQPuC6w6pulbYE2uurCzpEwoWvz_8Ps5ZjgtfomyY4LWacDEzlHLnyMj9H7aqgcePC7_4l2wDXQV-S0BQRsIZfJeUUmWxlTlLzvKZr_2eEx00YZPPFZNoFCfwB-ajLHLLenROy4aSjPo_Vg9o7N-p0DZ1yZQoJhkvoVJgkhX9FeAf65kIZkbuJC9dmVkzXSOpVf4GZeCpNDJJYSo6IAnL3UEoWek6V9BtWgV-a4xvydp7vxkdDXmzmalGLYuWbuVG7rWcbWwSfsg38iEG-mqptqA_Kzk1VmjwWNo_BfvLuzjzuosqi732-5SRzBP-2zqGghBqMYsGgkqkH2n7A | |
//human readable format | |
{ | |
"alg": "RS256" //header | |
} | |
{ | |
"sub": "user1" //claim payload | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment