JWTAuth jwt = JWTAuth.create(vertx, new JsonObject() .put("keyStore", new JsonObject() .put("type", "jceks") ctx.response().end(jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(60))); });
@Before public void setup() throws Exception { JsonObject authConfig = new JsonObject().put("keyStore", new JsonObject() .put("type", "jceks") .put("path", "keystore.jceks") .put("password", "secret")); authProvider = JWTAuth.create(vertx, new JWTAuthOptions(authConfig)); }
/** * Generate a new JWT token. * @param claims Json with user defined claims for a list of official claims * @param options extra options for the generation * @return JWT encoded token */ public String generateToken(JsonObject claims, JWTOptions options) { String ret = delegate.generateToken(claims, options); return ret; }
@Test public void testJWKShouldNotCrash() { authProvider = JWTAuth.create(vertx, new JWTAuthOptions().addJwk( new JsonObject() .put("kty", "RSA") .put("n", "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw") .put("e", "AQAB") .put("alg", "RS256") .put("kid", "2011-04-29"))); } }
public static JWT create(final JsonObject config, final Function<String, Buffer> funcBuffer) { return UxJwt.create(new JWTAuthOptions(config), funcBuffer); } }
public void start() { System.out.println(this); JWTAuth.create(vertx, config); } }
private JWTAuthOptions getConfig() { return new JWTAuthOptions() .setKeyStore(new KeyStoreOptions() .setPath("keystore.jceks") .setType("jceks") .setPassword("secret")); }
public static io.vertx.ext.auth.jwt.JWTAuth create(io.vertx.ext.auth.jwt.JWTAuth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.jwt.JWTAuth.create(vertx, config != null ? new io.vertx.ext.auth.jwt.JWTAuthOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(config)) : null)); } }
JWTAuth jwt = JWTAuth.create(vertx, new JsonObject() .put("keyStore", new JsonObject() .put("type", "jceks") ctx.response().end(jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(60).setPermissions (authorities))); });
/** * Generate a new JWT token. * @param claims Json with user defined claims for a list of official claims * @return JWT encoded token */ public String generateToken(JsonObject claims) { String ret = delegate.generateToken(claims); return ret; }
public static JWT create(final JsonObject config, final Function<String, Buffer> funcBuffer) { return UxJwt.create(new JWTAuthOptions(config), funcBuffer); } }
@Before public void setup() throws Exception { JsonObject authConfig = new JsonObject().put("keyStore", new JsonObject() .put("type", "jceks") .put("path", "keystore.jceks") .put("password", "secret")); authProvider = JWTAuth.create(vertx, new JWTAuthOptions(authConfig)); }
JWTAuth jwt = JWTAuth.create(vertx, new JsonObject() .put("keyStore", new JsonObject() .put("type", "jceks") ctx.response().end(jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(60).setPermissions (authorities))); });
/** * Generate a new JWT token. * @param claims Json with user defined claims for a list of official claims * @param options extra options for the generation * @return JWT encoded token */ public String generateToken(JsonObject claims, JWTOptions options) { String ret = delegate.generateToken(claims, options); return ret; }
public static JWT create(final JWTAuthOptions config) { return UxJwt.create(new JWTAuthOptions(config), Ut::ioBuffer); }
/** * Generate a new JWT token. * @param claims Json with user defined claims for a list of official claims * @return JWT encoded token */ public String generateToken(JsonObject claims) { String ret = delegate.generateToken(claims); return ret; }
public static JWT create(final JWTAuthOptions config) { return UxJwt.create(new JWTAuthOptions(config), Ut::ioBuffer); }
public static java.lang.String generateToken(io.vertx.ext.auth.jwt.JWTAuth j_receiver, java.util.Map<String, Object> claims) { return j_receiver.generateToken(claims != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(claims) : null); } }
@Test public void testLogin() throws Exception { Handler<RoutingContext> handler = rc -> { assertNotNull(rc.user()); assertEquals("paulo", rc.user().principal().getString("sub")); rc.response().end("Welcome to the protected resource!"); }; router.route("/protected/*").handler(JWTAuthHandler.create(authProvider)); router.route("/protected/somepage").handler(handler); testRequest(HttpMethod.GET, "/protected/somepage", null, resp -> { }, 401, "Unauthorized", null); // Now try again with credentials testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Bearer " + authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions())), 200, "OK", "Welcome to the protected resource!"); }
@Test public void testLoginFail() throws Exception { Handler<RoutingContext> handler = rc -> { fail("should not get here"); rc.response().end("Welcome to the protected resource!"); }; router.route("/protected/*").handler(JWTAuthHandler.create(authProvider)); router.route("/protected/somepage").handler(handler); testRequest(HttpMethod.GET, "/protected/somepage", null, 401, "Unauthorized", null); // Now try again with bad token final String token = authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions()); testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Bearer x" + token), 401, "Unauthorized", null); testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Basic " + token), 401, "Unauthorized", null); } }