use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project data-transfer-project by google.
the class GoogleAuthDataGenerator method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, String id, AuthData initialAuthData, String extra) {
Preconditions.checkState(initialAuthData == null, "Earlier auth data not expected for Google flow");
AuthorizationCodeFlow flow;
TokenResponse response;
try {
flow = createFlow();
response = flow.newTokenRequest(authCode).setRedirectUri(// TODO(chuy): Parameterize
callbackBaseUrl + redirectPath).execute();
} catch (IOException e) {
throw new RuntimeException("Error calling AuthorizationCodeFlow.execute ", e);
}
// Figure out storage
Credential credential = null;
try {
credential = flow.createAndStoreCredential(response, id);
} catch (IOException e) {
throw new RuntimeException("Error calling AuthorizationCodeFlow.createAndStoreCredential ", e);
}
// GoogleIdToken.Payload payload = ((GoogleTokenResponse) response).parseIdToken().getPayload();
return new TokensAndUrlAuthData(credential.getAccessToken(), credential.getRefreshToken(), credential.getTokenServerEncodedUrl());
}
use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project data-transfer-project by google.
the class GoogleAuth method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, UUID jobId, @Nullable AuthData initialAuthData, @Nullable String extra) throws IOException {
Preconditions.checkState(initialAuthData == null, "Earlier auth data not expected for Google flow");
AuthorizationCodeFlow flow = createFlow();
TokenResponse response = flow.newTokenRequest(authCode).setRedirectUri(// TODO(chuy): Parameterize
callbackBaseUrl + CALLBACK_PATH).execute();
// Figure out storage
Credential credential = flow.createAndStoreCredential(response, jobId.toString());
// GoogleIdToken.Payload payload = ((GoogleTokenResponse) response).parseIdToken().getPayload();
return toAuthData(credential);
}
use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project data-transfer-project by google.
the class InstagramAuth method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, UUID jobId, AuthData initialAuthData, String extra) throws IOException {
Preconditions.checkArgument(Strings.isNullOrEmpty(extra), "Extra data not expected for Instagram oauth flow");
Preconditions.checkArgument(initialAuthData == null, "Earlier auth data not expected for Instagram oauth flow");
AuthorizationCodeFlow flow = createFlow();
TokenResponse response = flow.newTokenRequest(authCode).setRedirectUri(// TODO(chuy): Parameterize
callbackBaseUrl + CALLBACK_PATH).execute();
// Figure out storage
Credential credential = flow.createAndStoreCredential(response, jobId.toString());
return toAuthData(credential);
}
use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project che by eclipse.
the class OAuthAuthenticator method configure.
/**
* This method should be invoked by child class for initialization default instance of {@link AuthorizationCodeFlow}
* that will be used for authorization
*/
protected void configure(String clientId, String clientSecret, String[] redirectUris, String authUri, String tokenUri, MemoryDataStoreFactory dataStoreFactory, List<String> scopes) throws IOException {
final AuthorizationCodeFlow authorizationFlow = new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(), new NetHttpTransport(), new JacksonFactory(), new GenericUrl(tokenUri), new ClientParametersAuthentication(clientId, clientSecret), clientId, authUri).setDataStoreFactory(dataStoreFactory).setScopes(scopes).build();
LOG.debug("clientId={}, clientSecret={}, redirectUris={} , authUri={}, tokenUri={}, dataStoreFactory={}", clientId, clientSecret, redirectUris, authUri, tokenUri, dataStoreFactory);
configure(authorizationFlow, Arrays.asList(redirectUris));
}
use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project data-transfer-project by google.
the class InstagramAuth method generateAuthData.
@Override
public AuthData generateAuthData(IOInterface ioInterface) throws IOException {
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(// Access Method
BearerToken.authorizationHeaderAccessMethod(), getTransport(), JSON_FACTORY, // GenericUrl
new GenericUrl("https://api.instagram.com/oauth/access_token"), new ClientParametersAuthentication(appCredentials.key(), appCredentials.secret()), // clientId
appCredentials.key(), // encoded authUrl
"https://api.instagram.com/oauth/authorize/").setScopes(// scopes
ImmutableList.of("basic", "public_content")).build();
VerificationCodeReceiver receiver = new LocalServerReceiver.Builder().setHost("localhost").setPort(12345).build();
try {
Credential result = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
return SecretAuthData.create(result.getAccessToken());
} catch (Exception e) {
throw new IOException("Couldn't authorize", e);
}
}
Aggregations