use of io.vertx.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();
}
use of io.vertx.ext.auth.oauth2.AccessToken in project data-transfer-project by google.
the class GoogleVideosImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor executor, TokensAndUrlAuthData authData, VideosContainerResource data) throws Exception {
if (data == null) {
// Nothing to do
return ImportResult.OK;
}
PhotosLibraryClient client;
if (clientsMap.containsKey(jobId)) {
client = clientsMap.get(jobId);
} else {
PhotosLibrarySettings settings = PhotosLibrarySettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(UserCredentials.newBuilder().setClientId(appCredentials.getKey()).setClientSecret(appCredentials.getSecret()).setAccessToken(new AccessToken(authData.getAccessToken(), new Date())).setRefreshToken(authData.getRefreshToken()).build())).build();
client = PhotosLibraryClient.initialize(settings);
clientsMap.put(jobId, client);
}
long bytes = 0L;
// Uploads videos
final Collection<VideoModel> videos = data.getVideos();
if (videos != null && videos.size() > 0) {
Stream<VideoModel> stream = videos.stream().filter(video -> shouldImport(video, executor)).map(this::transformVideoName);
// We partition into groups of 49 as 50 is the maximum number of items that can be created in
// one call. (We use 49 to avoid potential off by one errors)
// https://developers.google.com/photos/library/guides/upload-media#creating-media-item
final UnmodifiableIterator<List<VideoModel>> batches = Iterators.partition(stream.iterator(), 49);
while (batches.hasNext()) {
long batchBytes = importVideoBatch(batches.next(), client, executor);
bytes += batchBytes;
}
}
final ImportResult result = ImportResult.OK;
return result.copyWithBytes(bytes);
}
Aggregations