use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project vertx-auth by vert-x3.
the class OAuth2UserInfoTest method getUserInfoWithParams.
@Test
public void getUserInfoWithParams() {
final AccessToken accessToken = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, new JsonObject("{\"access_token\":\"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdXRob3JpemF0aW9uIjp7InBlcm1pc3Npb25zIjpbeyJyZXNvdXJjZV9zZXRfaWQiOiJkMmZlOTg0My02NDYyLTRiZmMtYmFiYS1iNTc4N2JiNmUwZTciLCJyZXNvdXJjZV9zZXRfbmFtZSI6IkhlbGxvIFdvcmxkIFJlc291cmNlIn1dfSwianRpIjoiZDYxMDlhMDktNzhmZC00OTk4LWJmODktOTU3MzBkZmQwODkyLTE0NjQ5MDY2Nzk0MDUiLCJleHAiOjk5OTk5OTk5OTksIm5iZiI6MCwiaWF0IjoxNDY0OTA2NjcxLCJzdWIiOiJmMTg4OGY0ZC01MTcyLTQzNTktYmUwYy1hZjMzODUwNWQ4NmMiLCJ0eXAiOiJrY19ldHQiLCJhenAiOiJoZWxsby13b3JsZC1hdXRoei1zZXJ2aWNlIn0\",\"active\":true,\"scope\":\"scopeA scopeB\",\"client_id\":\"client-id\",\"username\":\"username\",\"token_type\":\"bearer\",\"expires_at\":99999999999000}"));
accessToken.userInfo(userInfo -> {
if (userInfo.failed()) {
fail(userInfo.cause().getMessage());
} else {
assertEquals(fixture, userInfo.result());
testComplete();
}
});
await();
}
use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project vertx-auth by vert-x3.
the class AuthCodeImpl method getToken.
/**
* Returns the Access Token object.
*
* @param params - code: Authorization code (from previous step).
* redirectURI: A String that represents the callback uri.
* @param handler - The handler returning the results.
*/
@Override
public void getToken(JsonObject params, Handler<AsyncResult<AccessToken>> handler) {
getToken("authorization_code", 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));
});
}
use of io.vertx.reactivex.ext.auth.oauth2.AccessToken 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));
});
}
use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project vertx-auth by vert-x3.
the class OAuth2AccessTokenTest method tokenShouldNotBeExpired.
@Test
public void tokenShouldNotBeExpired() {
config = oauthConfig;
oauth2.authenticate(tokenConfig, res -> {
if (res.failed()) {
fail(res.cause().getMessage());
} else {
AccessToken token = (AccessToken) res.result();
assertFalse(token.expired());
testComplete();
}
});
await();
}
use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project vertx-auth by vert-x3.
the class OAuth2AccessTokenTest method tokenShouldBeExpiredWhenExpirationDateIsInThePast.
@Test
public void tokenShouldBeExpiredWhenExpirationDateIsInThePast() {
config = oauthConfig;
oauth2.authenticate(tokenConfig, res -> {
if (res.failed()) {
fail(res.cause().getMessage());
} else {
AccessToken token = (AccessToken) res.result();
// hack the token to set the expires_at (to yesterday)
token.principal().put("expires_at", System.currentTimeMillis() - 24 * 60 * 60 * 1000);
assertTrue(token.expired());
testComplete();
}
});
await();
}
Aggregations