X Tutup
Skip to content

Accept Array type on verification and creation.#123

Merged
hzalaz merged 6 commits intomasterfrom
feat-accept-more-types
Jan 4, 2017
Merged

Accept Array type on verification and creation.#123
hzalaz merged 6 commits intomasterfrom
feat-accept-more-types

Conversation

@lbalmaceda
Copy link
Copy Markdown
Contributor

@lbalmaceda lbalmaceda commented Dec 14, 2016

Now we can specify Arrays of type String or Integer for creation/verification of JWTs.

  1. Get a Claim as a custom class:
Claim claim = jwt.getClaim("user");
UserProfile user = claim.as(UserProfile.class);
  1. Create a token with an Array Claim:
String jwt = JWTCreator.init()
                .withArrayClaim("name", new String[]{"a", "b", "c"})
                .sign(Algorithm.HMAC256("secret"));
  1. Verify that a token contains an Array Claim with at least specific items:
DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
                .withArrayClaim("name", "a", "b")
                .build()
                .verify(token);

Note that in this example, UserProfile class must have a no-args public constructor for deserialization to work.

@lbalmaceda
Copy link
Copy Markdown
Contributor Author

Adds the features discussed in #117

@lbalmaceda lbalmaceda force-pushed the feat-accept-more-types branch 2 times, most recently from 3842dc5 to 4b07586 Compare December 14, 2016 21:06
@lbalmaceda lbalmaceda force-pushed the feat-accept-more-types branch from 4b07586 to 91097b4 Compare December 14, 2016 21:35
@lbalmaceda lbalmaceda changed the title Accept all class types in verification and creation. Accept Array type on verification and creation. Dec 16, 2016
@hzalaz hzalaz added this to the 3.1.0 milestone Jan 4, 2017
@hzalaz hzalaz merged commit 9148ca2 into master Jan 4, 2017
@hzalaz hzalaz deleted the feat-accept-more-types branch January 4, 2017 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup