use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testExpiration.
@Test
public void testExpiration() {
JsonObject payload = new JsonObject().put("sub", "Paulo");
final String token = authProvider.generateToken(payload, new JWTOptions().setExpiresInSeconds(1).setNoTimestamp(true));
assertNotNull(token);
vertx.setTimer(2000L, t -> {
JsonObject authInfo = new JsonObject().put("jwt", token);
authProvider.authenticate(authInfo, onFailure(thr -> {
assertNotNull(thr);
testComplete();
}));
});
await();
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testGenerateNewTokenImmutableClaims.
@Test
public void testGenerateNewTokenImmutableClaims() {
JsonObject payload = new JsonObject().put("sub", "Paulo");
String token0 = authProvider.generateToken(payload, new JWTOptions().addPermission("user"));
String token1 = authProvider.generateToken(payload, new JWTOptions().addPermission("admin"));
assertNotEquals(token0, token1);
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testLeeway2.
@Test
public void testLeeway2() {
authProvider = JWTAuth.create(vertx, getConfig().setJWTOptions(new JWTOptions().setLeeway(0)));
long now = (System.currentTimeMillis() / 1000) + 2;
JsonObject payload = new JsonObject().put("sub", "Paulo").put("iat", now);
String token = authProvider.generateToken(payload);
assertNotNull(token);
JsonObject authInfo = new JsonObject().put("jwt", token);
// fail because iat is > now (clock drifted 2 sec)
authProvider.authenticate(authInfo, onFailure(t -> testComplete()));
await();
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testTokenWithoutTimestamp.
@Test
public void testTokenWithoutTimestamp() {
JsonObject payload = new JsonObject().put("sub", "Paulo");
final String token = authProvider.generateToken(payload, new JWTOptions().setExpiresInMinutes(5).setNoTimestamp(true));
assertNotNull(token);
JsonObject authInfo = new JsonObject().put("jwt", token);
authProvider.authenticate(authInfo, onSuccess(res -> {
assertNotNull(res);
assertTrue(res.principal().containsKey("exp"));
assertFalse(res.principal().containsKey("iat"));
testComplete();
}));
await();
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testGenerateNewTokenES256.
@Test
public void testGenerateNewTokenES256() {
authProvider = JWTAuth.create(vertx, new JWTAuthOptions().setKeyStore(new KeyStoreOptions().setPath("es256-keystore.jceks").setPassword("secret")));
String token = authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions().setAlgorithm("ES256"));
assertNotNull(token);
JsonObject authInfo = new JsonObject().put("jwt", token);
authProvider.authenticate(authInfo, res -> {
if (res.failed()) {
res.cause().printStackTrace();
fail();
}
assertNotNull(res.result());
testComplete();
});
await();
}
Aggregations