use of com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver 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);
}
}
use of com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver in project data-transfer-project by google.
the class MicrosoftAuth method getAuthData.
/**
* Initiates the auth flow and obtains the access token.
*/
private MicrosoftOauthData getAuthData(String account) throws IOException {
// set up authorization code flow
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(// Access Method
BearerToken.authorizationHeaderAccessMethod(), // HttpTransport
MicrosoftStaticObjects.getHttpTransport(), // JsonFactory
JSON_FACTORY, // GenericUrl
new GenericUrl(TOKEN_SERVER_URL), new ClientParametersAuthentication(appCredentials.key(), appCredentials.secret()), // clientId
appCredentials.key(), // encoded authUrl
AUTHORIZATION_SERVER_URL).setScopes(// scopes
scopes).setDataStoreFactory(MicrosoftStaticObjects.getDataStoreFactory()).build();
// authorize
// NOTE: This requires an https endpoint wired to
// forward requests to http://domain:port/Callback
VerificationCodeReceiver receiver = new LocalServerReceiver.Builder().setHost(DOMAIN).setPort(PORT).build();
try {
Credential credential = new AuthorizationCodeInstalledAppSecureOverride(flow, receiver).authorize(account);
return toAuthData(credential);
} catch (Exception e) {
throw new IOException("Couldn't authorize", e);
}
}
use of com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver in project community by GoogleCloudPlatform.
the class SimpleExample method authorize.
private Credential authorize() throws Exception {
HttpExecuteInterceptor credentials = new ClientParametersAuthentication(this.clientId, this.clientSecret);
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(authorizationHeaderAccessMethod(), httpTransport, jsonFactory, new GenericUrl(TOKEN_SERVER_URL), credentials, this.clientId, AUTHORIZATION_SERVER_URL).setScopes(SCOPES).setDataStoreFactory(dataStoreFactory).build();
LocalServerReceiver.Builder builder = new LocalServerReceiver.Builder();
VerificationCodeReceiver receiver = builder.setHost(DOMAIN).setPort(PORT).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
Aggregations