Search in sources :

Example 11 with OAuth2TokenImpl

use of io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl in project vertx-auth by vert-x3.

the class PasswordImpl method getToken.

/**
 * Returns the Access Token object.
 *
 * @param params - username: A string that represents the registered username.
 *                 password: A string that represents the registered password.
 *                 scope:    A String that represents the application privileges.
 * @param handler - The handler function returning the results.
 */
@Override
public void getToken(JsonObject params, Handler<AsyncResult<AccessToken>> handler) {
    getToken("password", params, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
            return;
        }
        AccessToken token;
        try {
            token = new OAuth2TokenImpl(provider, res.result());
        } catch (RuntimeException e) {
            handler.handle(Future.failedFuture(e));
            return;
        }
        handler.handle(Future.succeededFuture(token));
    });
}
Also used : AccessToken(io.vertx.ext.auth.oauth2.AccessToken) OAuth2TokenImpl(io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)

Example 12 with OAuth2TokenImpl

use of io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl in project vertx-auth by vert-x3.

the class Oauth2TokenTest method testNullScope.

@Test
public void testNullScope() throws Exception {
    super.setUp();
    oauth2 = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, keycloakConfig);
    JsonObject json = new JsonObject("{\n" + "    \"access_token\":\"xyz\",\n" + "    \"expires_in\":60,\n" + "    \"token_type\":\"bearer\",\n" + "    \"not-before-policy\":0,\n" + "    \"scope\":null\n" + "}");
    try {
        OAuth2TokenImpl token = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, json);
    } catch (RuntimeException e) {
        fail();
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) OAuth2TokenImpl(io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl) Test(org.junit.Test)

Example 13 with OAuth2TokenImpl

use of io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl in project vertx-auth by vert-x3.

the class Oauth2TokenTest method keycloakTest.

@Test
public void keycloakTest() throws Exception {
    super.setUp();
    oauth2 = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, keycloakConfig);
    OAuth2TokenImpl token = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, keycloakToken);
    assertNotNull(token.opaqueAccessToken());
    assertNotNull(token.opaqueRefreshToken());
    assertNull(token.accessToken());
    // trust it
    token.setTrustJWT(true);
    assertNotNull(token.accessToken());
}
Also used : OAuth2TokenImpl(io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl) Test(org.junit.Test)

Aggregations

OAuth2TokenImpl (io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)11 JsonObject (io.vertx.core.json.JsonObject)8 AccessToken (io.vertx.ext.auth.oauth2.AccessToken)5 Test (org.junit.Test)5 OAuth2Response (io.vertx.ext.auth.oauth2.OAuth2Response)3 Buffer (io.vertx.core.buffer.Buffer)2 OAuth2AuthProviderImpl (io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl)2 AccessToken (io.vertx.reactivex.ext.auth.oauth2.AccessToken)2 OAuth2Auth (io.vertx.ext.auth.oauth2.OAuth2Auth)1 Session (io.vertx.reactivex.ext.web.Session)1