use of io.vertx.ext.auth.jwt.JWTAuth in project vertx-auth by vert-x3.
the class AuthJWTExamples method example18.
public void example18(Vertx vertx) {
JWTAuth provider = JWTAuth.create(vertx, new JWTAuthOptions().addPubSecKey(new PubSecKeyOptions().setAlgorithm("ES256").setPublicKey("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEraVJ8CpkrwTPRCPluUDdwC6b8+m4\n" + "dEjwl8s+Sn0GULko+H95fsTREQ1A2soCFHS4wV3/23Nebq9omY3KuK9DKw==\n").setSecretKey("MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgeRyEfU1NSHPTCuC9\n" + "rwLZMukaWCH2Fk6q5w+XBYrKtLihRANCAAStpUnwKmSvBM9EI+W5QN3ALpvz6bh0\n" + "SPCXyz5KfQZQuSj4f3l+xNERDUDaygIUdLjBXf/bc15ur2iZjcq4r0Mr")));
String token = provider.generateToken(new JsonObject(), new io.vertx.ext.jwt.JWTOptions().setAlgorithm("ES256"));
}
use of io.vertx.ext.auth.jwt.JWTAuth in project vertx-auth by vert-x3.
the class AuthJWTExamples method example16.
public void example16(Vertx vertx) {
JWTAuth provider = JWTAuth.create(vertx, new JWTAuthOptions().addPubSecKey(new PubSecKeyOptions().setAlgorithm("HS256").setPublicKey("keyboard cat").setSymmetric(true)));
String token = provider.generateToken(new JsonObject());
}
use of io.vertx.ext.auth.jwt.JWTAuth in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
// Create a JWT Auth Provider
JWTAuth jwt = JWTAuth.create(vertx, new JsonObject().put("keyStore", new JsonObject().put("type", "jceks").put("path", "keystore.jceks").put("password", "secret")));
// protect the API
router.route("/api/*").handler(JWTAuthHandler.create(jwt, "/api/newToken"));
// this route is excluded from the auth handler
router.get("/api/newToken").handler(ctx -> {
ctx.response().putHeader("Content-Type", "text/plain");
ctx.response().end(jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(60)));
});
// this is the secret API
router.get("/api/protected").handler(ctx -> {
ctx.response().putHeader("Content-Type", "text/plain");
ctx.response().end("a secret you should keep for yourself...");
});
// Serve the non private static pages
router.route().handler(StaticHandler.create());
vertx.createHttpServer().requestHandler(router).listen(8080);
}
Aggregations