use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testGenerateNewToken.
@Test
public void testGenerateNewToken() {
JsonObject payload = new JsonObject().put("sub", "Paulo").put("exp", 1747055313).put("iat", 1431695313).put("permissions", new JsonArray().add("read").add("write").add("execute")).put("roles", new JsonArray().add("admin").add("developer").add("user"));
String token = authProvider.generateToken(payload, new JWTOptions().setSubject("Paulo"));
assertNotNull(token);
assertEquals(JWT_VALID, token);
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testGoodAudience.
@Test
public void testGoodAudience() {
JsonObject payload = new JsonObject().put("sub", "Paulo");
final String token = authProvider.generateToken(payload, new JWTOptions().addAudience("a").addAudience("b").addAudience("c"));
assertNotNull(token);
JsonObject authInfo = new JsonObject().put("jwt", token).put("options", new JsonObject().put("audience", new JsonArray().add("b").add("d")));
authProvider.authenticate(authInfo, onSuccess(res -> {
assertNotNull(res);
testComplete();
}));
await();
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testLeeway3.
@Test
public void testLeeway3() {
authProvider = JWTAuth.create(vertx, getConfig().setJWTOptions(new JWTOptions().setLeeway(5)));
long now = System.currentTimeMillis() / 1000;
JsonObject payload = new JsonObject().put("sub", "Paulo").put("exp", now).put("iat", now);
String token = authProvider.generateToken(payload);
assertNotNull(token);
JsonObject authInfo = new JsonObject().put("jwt", token);
// fail because exp is <= to now
authProvider.authenticate(authInfo, onSuccess(t -> testComplete()));
await();
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testGenerateNewTokenWithMacSecret.
@Test
public void testGenerateNewTokenWithMacSecret() {
authProvider = JWTAuth.create(vertx, new JWTAuthOptions().addSecret(new SecretOptions().setType("HS256").setSecret("notasecret")));
String token = authProvider.generateToken(new JsonObject(), new JWTOptions().setAlgorithm("HS256"));
assertNotNull(token);
// reverse
JsonObject authInfo = new JsonObject().put("jwt", token);
authProvider.authenticate(authInfo, onSuccess(res -> {
assertNotNull(res);
testComplete();
}));
await();
}
use of io.vertx.ext.jwt.JWTOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testLeeway.
@Test
public void testLeeway() {
authProvider = JWTAuth.create(vertx, getConfig().setJWTOptions(new JWTOptions().setLeeway(0)));
long now = System.currentTimeMillis() / 1000;
JsonObject payload = new JsonObject().put("sub", "Paulo").put("exp", now);
String token = authProvider.generateToken(payload);
assertNotNull(token);
JsonObject authInfo = new JsonObject().put("jwt", token);
// fail because exp is <= to now
authProvider.authenticate(authInfo, onFailure(t -> testComplete()));
await();
}
Aggregations