Search in sources :

Example 11 with JWTAuth

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"));
}
Also used : JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) PubSecKeyOptions(io.vertx.ext.auth.PubSecKeyOptions) JsonObject(io.vertx.core.json.JsonObject) JWTOptions(io.vertx.ext.auth.jwt.JWTOptions) JWTAuth(io.vertx.ext.auth.jwt.JWTAuth)

Example 12 with JWTAuth

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());
}
Also used : JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) PubSecKeyOptions(io.vertx.ext.auth.PubSecKeyOptions) JsonObject(io.vertx.core.json.JsonObject) JWTAuth(io.vertx.ext.auth.jwt.JWTAuth)

Example 13 with JWTAuth

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);
}
Also used : Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) JWTOptions(io.vertx.ext.jwt.JWTOptions) JWTAuth(io.vertx.ext.auth.jwt.JWTAuth)

Aggregations

JWTAuth (io.vertx.ext.auth.jwt.JWTAuth)13 JsonObject (io.vertx.core.json.JsonObject)12 JWTAuthOptions (io.vertx.ext.auth.jwt.JWTAuthOptions)10 KeyStoreOptions (io.vertx.ext.auth.KeyStoreOptions)5 PubSecKeyOptions (io.vertx.ext.auth.PubSecKeyOptions)4 JWTOptions (io.vertx.ext.auth.jwt.JWTOptions)4 JWTOptions (io.vertx.ext.jwt.JWTOptions)4 Router (io.vertx.ext.web.Router)3 JWTOptions (io.vertx.ext.auth.JWTOptions)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 JsonArray (io.vertx.core.json.JsonArray)1 SecretOptions (io.vertx.ext.auth.SecretOptions)1 VertxTestBase (io.vertx.test.core.VertxTestBase)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Base64 (java.util.Base64)1 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)1