Search in sources :

Example 11 with JWTAuthOptions

use of io.vertx.ext.auth.jwt.JWTAuthOptions in project vertx-auth by vert-x3.

the class JWTAuthProviderTest method testValidateTokenWithValidMacSecret.

@Test
public void testValidateTokenWithValidMacSecret() {
    String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MDE3ODUyMDZ9.08K_rROcCmKTF1cKfPCli2GQFYIOP8dePxeS1SE4dc8";
    authProvider = JWTAuth.create(vertx, new JWTAuthOptions().addSecret(new SecretOptions().setType("HS256").setSecret("notasecret")));
    JsonObject authInfo = new JsonObject().put("jwt", token);
    authProvider.authenticate(authInfo, onSuccess(res -> {
        assertNotNull(res);
        testComplete();
    }));
    await();
}
Also used : SecretOptions(io.vertx.ext.auth.SecretOptions) KeyStoreOptions(io.vertx.ext.auth.KeyStoreOptions) JsonArray(io.vertx.core.json.JsonArray) Base64(java.util.Base64) JWTOptions(io.vertx.ext.jwt.JWTOptions) SecretOptions(io.vertx.ext.auth.SecretOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test) JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) JWTAuth(io.vertx.ext.auth.jwt.JWTAuth) VertxTestBase(io.vertx.test.core.VertxTestBase) StandardCharsets(java.nio.charset.StandardCharsets) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 12 with JWTAuthOptions

use of io.vertx.ext.auth.jwt.JWTAuthOptions in project vertx-auth by vert-x3.

the class AuthJWTExamples method example17.

public void example17(Vertx vertx) {
    JWTAuth provider = JWTAuth.create(vertx, new JWTAuthOptions().addPubSecKey(new PubSecKeyOptions().setAlgorithm("ES256").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 13 with JWTAuthOptions

use of io.vertx.ext.auth.jwt.JWTAuthOptions 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 14 with JWTAuthOptions

use of io.vertx.ext.auth.jwt.JWTAuthOptions 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)

Aggregations

JWTAuthOptions (io.vertx.ext.auth.jwt.JWTAuthOptions)14 JsonObject (io.vertx.core.json.JsonObject)12 JWTAuth (io.vertx.ext.auth.jwt.JWTAuth)10 KeyStoreOptions (io.vertx.ext.auth.KeyStoreOptions)8 JsonArray (io.vertx.core.json.JsonArray)6 JWTOptions (io.vertx.ext.jwt.JWTOptions)6 Test (org.junit.Test)6 PubSecKeyOptions (io.vertx.ext.auth.PubSecKeyOptions)5 SecretOptions (io.vertx.ext.auth.SecretOptions)5 VertxTestBase (io.vertx.test.core.VertxTestBase)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Base64 (java.util.Base64)5 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)5 JWTOptions (io.vertx.ext.auth.jwt.JWTOptions)4 AuthProvider (io.vertx.ext.auth.AuthProvider)2 JWT (io.vertx.ext.jwt.JWT)1