Search in sources :

Example 1 with OAuth2FlowType

use of io.vertx.ext.auth.oauth2.OAuth2FlowType 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 OAuth2FlowType

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

Aggregations

PubSecKeyOptions (io.vertx.ext.auth.PubSecKeyOptions)2 OAuth2ClientOptions (io.vertx.ext.auth.oauth2.OAuth2ClientOptions)1 OAuth2AuthProviderImpl (io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl)1