Search in sources :

Example 6 with Token

use of com.auth0.json.mgmt.Token in project sda-dropwizard-commons by SDA-SE.

the class AuthBuilderTest method shouldOverwriteClaimOnMultipleAddCalls.

@Test
public void shouldOverwriteClaimOnMultipleAddCalls() {
    String token = authBuilder.addClaim("test", 1L).addClaim("test", 2).addClaim("test", "foo").buildToken();
    DecodedJWT jwt = JWT.decode(token);
    assertThat(jwt.getClaim("test").asLong()).isNull();
    assertThat(jwt.getClaim("test").asInt()).isNull();
    assertThat(jwt.getClaim("test").asString()).isEqualTo("foo");
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Test(org.junit.Test)

Example 7 with Token

use of com.auth0.json.mgmt.Token in project sda-dropwizard-commons by SDA-SE.

the class AuthBuilderTest method shouldAddStringArrayClaim.

@Test
public void shouldAddStringArrayClaim() {
    String token = authBuilder.addClaim("testKey", new String[] { "Hello", "World" }).buildToken();
    Claim claim = JWT.decode(token).getClaim("testKey");
    assertThat(claim.asList(String.class)).containsExactly("Hello", "World");
}
Also used : Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 8 with Token

use of com.auth0.json.mgmt.Token in project sda-dropwizard-commons by SDA-SE.

the class AuthBuilderTest method shouldAddBooleanClaim.

@Test
public void shouldAddBooleanClaim() {
    String token = authBuilder.addClaim("testKey", true).buildToken();
    Claim claim = JWT.decode(token).getClaim("testKey");
    assertThat(claim.asBoolean()).isTrue();
}
Also used : Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 9 with Token

use of com.auth0.json.mgmt.Token in project sda-dropwizard-commons by SDA-SE.

the class AuthBuilderTest method shouldAddLongArrayClaim.

@Test
public void shouldAddLongArrayClaim() {
    String token = authBuilder.addClaim("testKey", new Long[] { 1L, 2L }).buildToken();
    Claim claim = JWT.decode(token).getClaim("testKey");
    assertThat(claim.asList(Long.class)).containsExactly(1L, 2L);
}
Also used : Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 10 with Token

use of com.auth0.json.mgmt.Token in project sda-dropwizard-commons by SDA-SE.

the class AuthBuilderTest method shouldAddIntArrayClaim.

@Test
public void shouldAddIntArrayClaim() {
    String token = authBuilder.addClaim("testKey", new Integer[] { 1, 2 }).buildToken();
    Claim claim = JWT.decode(token).getClaim("testKey");
    assertThat(claim.asList(Integer.class)).containsExactly(1, 2);
}
Also used : Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Aggregations

DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)276 Algorithm (com.auth0.jwt.algorithms.Algorithm)147 Test (org.junit.Test)120 JWTVerifier (com.auth0.jwt.JWTVerifier)97 Date (java.util.Date)78 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)62 IOException (java.io.IOException)59 Claim (com.auth0.jwt.interfaces.Claim)49 HashMap (java.util.HashMap)40 VoidRequest (com.auth0.net.VoidRequest)31 RSAPublicKey (java.security.interfaces.RSAPublicKey)31 Test (org.junit.jupiter.api.Test)30 JWTDecodeException (com.auth0.jwt.exceptions.JWTDecodeException)28 JWTCreator (com.auth0.jwt.JWTCreator)21 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)21 JWT (com.auth0.jwt.JWT)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 Instant (java.time.Instant)18 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)17