Search in sources :

Example 1 with PubSecKeyOptions

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

the class OAuth2Auth method createKeycloak.

/**
 * @deprecated You should use the provider helper {@link io.vertx.ext.auth.oauth2.providers.KeycloakAuth} instead.
 *
 * Create a OAuth2 auth provider
 *
 * @param vertx the Vertx instance
 * @param config  the config as exported from the admin console
 * @return the auth provider
 */
@Deprecated
static OAuth2Auth createKeycloak(Vertx vertx, OAuth2FlowType flow, JsonObject config) {
    final OAuth2ClientOptions options = new OAuth2ClientOptions();
    // keycloak conversion to oauth2 options
    if (config.containsKey("auth-server-url")) {
        options.setSite(config.getString("auth-server-url"));
    }
    if (config.containsKey("resource")) {
        options.setClientID(config.getString("resource"));
    }
    if (config.containsKey("credentials") && config.getJsonObject("credentials").containsKey("secret")) {
        options.setClientSecret(config.getJsonObject("credentials").getString("secret"));
    }
    if (config.containsKey("public-client") && config.getBoolean("public-client", false)) {
        options.setUseBasicAuthorizationHeader(true);
    }
    if (config.containsKey("realm")) {
        final String realm = config.getString("realm");
        options.setAuthorizationPath("/realms/" + realm + "/protocol/openid-connect/auth");
        options.setTokenPath("/realms/" + realm + "/protocol/openid-connect/token");
        options.setRevocationPath(null);
        options.setLogoutPath("/realms/" + realm + "/protocol/openid-connect/logout");
        options.setUserInfoPath("/realms/" + realm + "/protocol/openid-connect/userinfo");
    }
    if (config.containsKey("realm-public-key")) {
        options.addPubSecKey(new PubSecKeyOptions().setAlgorithm("RS256").setPublicKey(config.getString("realm-public-key")));
    }
    return new OAuth2AuthProviderImpl(vertx, flow, options);
}
Also used : PubSecKeyOptions(io.vertx.ext.auth.PubSecKeyOptions) OAuth2AuthProviderImpl(io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl)

Example 2 with PubSecKeyOptions

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

the class KeycloakAuth method create.

/**
 * Create a OAuth2Auth provider for Keycloak
 *
 * @param flow              the oauth2 flow to use
 * @param config            the json config file exported from Keycloak admin console
 * @param httpClientOptions custom http client options
 */
static OAuth2Auth create(Vertx vertx, OAuth2FlowType flow, JsonObject config, HttpClientOptions httpClientOptions) {
    final OAuth2ClientOptions options = new OAuth2ClientOptions(httpClientOptions);
    // keycloak conversion to oauth2 options
    if (config.containsKey("auth-server-url")) {
        options.setSite(config.getString("auth-server-url"));
    }
    if (config.containsKey("resource")) {
        options.setClientID(config.getString("resource"));
    }
    if (config.containsKey("credentials") && config.getJsonObject("credentials").containsKey("secret")) {
        options.setClientSecret(config.getJsonObject("credentials").getString("secret"));
    }
    if (config.containsKey("public-client") && config.getBoolean("public-client", false)) {
        options.setUseBasicAuthorizationHeader(true);
    }
    if (config.containsKey("realm")) {
        final String realm = config.getString("realm");
        options.setAuthorizationPath("/realms/" + realm + "/protocol/openid-connect/auth");
        options.setTokenPath("/realms/" + realm + "/protocol/openid-connect/token");
        options.setRevocationPath(null);
        options.setLogoutPath("/realms/" + realm + "/protocol/openid-connect/logout");
        options.setUserInfoPath("/realms/" + realm + "/protocol/openid-connect/userinfo");
        // keycloak follows the RFC7662
        options.setIntrospectionPath("/realms/" + realm + "/protocol/openid-connect/token/introspect");
        // keycloak follows the RFC7517
        options.setJwkPath("/realms/" + realm + "/protocol/openid-connect/certs");
    }
    if (config.containsKey("realm-public-key")) {
        options.addPubSecKey(new PubSecKeyOptions().setAlgorithm("RS256").setPublicKey(config.getString("realm-public-key")));
        // we could load keys
        options.setJWTToken(true);
    }
    return OAuth2Auth.create(vertx, flow, options);
}
Also used : PubSecKeyOptions(io.vertx.ext.auth.PubSecKeyOptions) OAuth2ClientOptions(io.vertx.ext.auth.oauth2.OAuth2ClientOptions)

Example 3 with PubSecKeyOptions

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

the class AuthJWTExamples method example15.

public void example15(Vertx vertx) {
    JWTAuth provider = JWTAuth.create(vertx, new JWTAuthOptions().addPubSecKey(new PubSecKeyOptions().setAlgorithm("RS256").setP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yL\n" + "0fPinYmDJpkwMYHqQaLGQyg=")));
    String token = provider.generateToken(new JsonObject(), new io.vertx.ext.jwt.JWTOptions().setAlgorithm("RS256"));
}
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 4 with PubSecKeyOptions

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

the class AuthJWTExamples method example8.

public void example8(Vertx vertx) {
    JWTAuthOptions config = new JWTAuthOptions().addPubSecKey(new PubSecKeyOptions().setAlgorithm("RS256").setPublicKey("BASE64-ENCODED-PUBLIC_KEY"));
    AuthProvider provider = JWTAuth.create(vertx, config);
}
Also used : JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) PubSecKeyOptions(io.vertx.ext.auth.PubSecKeyOptions) AuthProvider(io.vertx.ext.auth.AuthProvider)

Example 5 with PubSecKeyOptions

use of io.vertx.ext.auth.PubSecKeyOptions in project vertx-zero by silentbalanceyh.

the class UxJwt method createDirect.

private static JWT createDirect(final JWTAuthOptions config, final Function<String, Buffer> funcBuffer) {
    final JWT reference;
    final KeyStoreOptions keyStore = config.getKeyStore();
    try {
        if (keyStore != null) {
            final KeyStore ks = KeyStore.getInstance(keyStore.getType());
            final Class var5 = JwtAuthProvider.class;
            synchronized (JwtAuthProvider.class) {
                final Buffer keystore = funcBuffer.apply(keyStore.getPath());
                final InputStream in = new ByteArrayInputStream(keystore.getBytes());
                Throwable var8 = null;
                try {
                    ks.load(in, keyStore.getPassword().toCharArray());
                } catch (final Throwable var20) {
                    var8 = var20;
                    throw var20;
                } finally {
                    if (in != null) {
                        if (var8 != null) {
                            try {
                                in.close();
                            } catch (final Throwable var19) {
                                var8.addSuppressed(var19);
                            }
                        } else {
                            in.close();
                        }
                    }
                }
            }
            reference = new JWT(ks, keyStore.getPassword().toCharArray());
        } else {
            reference = new JWT();
            final List<PubSecKeyOptions> keys = config.getPubSecKeys();
            if (keys != null) {
                final Iterator var25 = config.getPubSecKeys().iterator();
                while (var25.hasNext()) {
                    final PubSecKeyOptions pubSecKey = (PubSecKeyOptions) var25.next();
                    if (pubSecKey.isSymmetric()) {
                        reference.addJWK(new JWK(pubSecKey.getAlgorithm(), pubSecKey.getPublicKey()));
                    } else {
                        reference.addJWK(new JWK(pubSecKey.getAlgorithm(), pubSecKey.isCertificate(), pubSecKey.getPublicKey(), pubSecKey.getSecretKey()));
                    }
                }
            }
            final List<SecretOptions> secrets = config.getSecrets();
            if (secrets != null) {
                final Iterator var28 = secrets.iterator();
                while (var28.hasNext()) {
                    final SecretOptions secret = (SecretOptions) var28.next();
                    reference.addSecret(secret.getType(), secret.getSecret());
                }
            }
        }
    } catch (IOException | FileSystemException | CertificateException | NoSuchAlgorithmException | KeyStoreException var23) {
        throw new _500JwtRuntimeException(UxJwt.class, var23);
    }
    return reference;
}
Also used : Buffer(io.vertx.core.buffer.Buffer) io.vertx.up.exception._500JwtRuntimeException(io.vertx.up.exception._500JwtRuntimeException) PubSecKeyOptions(io.vertx.ext.auth.PubSecKeyOptions) JWT(io.vertx.ext.jwt.JWT) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) KeyStoreOptions(io.vertx.ext.auth.KeyStoreOptions) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) SecretOptions(io.vertx.ext.auth.SecretOptions) FileSystemException(io.vertx.core.file.FileSystemException) ByteArrayInputStream(java.io.ByteArrayInputStream) JwtAuthProvider(io.vertx.up.secure.provider.JwtAuthProvider) Iterator(java.util.Iterator) JWK(io.vertx.ext.jwt.JWK)

Aggregations

PubSecKeyOptions (io.vertx.ext.auth.PubSecKeyOptions)8 JWTAuthOptions (io.vertx.ext.auth.jwt.JWTAuthOptions)5 JsonObject (io.vertx.core.json.JsonObject)4 JWTAuth (io.vertx.ext.auth.jwt.JWTAuth)4 JWTOptions (io.vertx.ext.auth.jwt.JWTOptions)3 Buffer (io.vertx.core.buffer.Buffer)1 FileSystemException (io.vertx.core.file.FileSystemException)1 AuthProvider (io.vertx.ext.auth.AuthProvider)1 KeyStoreOptions (io.vertx.ext.auth.KeyStoreOptions)1 SecretOptions (io.vertx.ext.auth.SecretOptions)1 OAuth2ClientOptions (io.vertx.ext.auth.oauth2.OAuth2ClientOptions)1 OAuth2AuthProviderImpl (io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl)1 JWK (io.vertx.ext.jwt.JWK)1 JWT (io.vertx.ext.jwt.JWT)1 io.vertx.up.exception._500JwtRuntimeException (io.vertx.up.exception._500JwtRuntimeException)1 JwtAuthProvider (io.vertx.up.secure.provider.JwtAuthProvider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 KeyStore (java.security.KeyStore)1