Search in sources :

Example 1 with VerificationCodeReceiver

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);
    }
}
Also used : ClientParametersAuthentication(com.google.api.client.auth.oauth2.ClientParametersAuthentication) Credential(com.google.api.client.auth.oauth2.Credential) VerificationCodeReceiver(com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver) AuthorizationCodeInstalledApp(com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp) GenericUrl(com.google.api.client.http.GenericUrl) LocalServerReceiver(com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow)

Example 2 with VerificationCodeReceiver

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);
    }
}
Also used : AuthorizationCodeInstalledAppSecureOverride(org.dataportabilityproject.shared.auth.AuthorizationCodeInstalledAppSecureOverride) ClientParametersAuthentication(com.google.api.client.auth.oauth2.ClientParametersAuthentication) Credential(com.google.api.client.auth.oauth2.Credential) VerificationCodeReceiver(com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver) GenericUrl(com.google.api.client.http.GenericUrl) LocalServerReceiver(com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver) IOException(java.io.IOException) IOException(java.io.IOException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow)

Example 3 with VerificationCodeReceiver

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");
}
Also used : ClientParametersAuthentication(com.google.api.client.auth.oauth2.ClientParametersAuthentication) VerificationCodeReceiver(com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver) AuthorizationCodeInstalledApp(com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp) LocalServerReceiver(com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow)

Aggregations

AuthorizationCodeFlow (com.google.api.client.auth.oauth2.AuthorizationCodeFlow)3 ClientParametersAuthentication (com.google.api.client.auth.oauth2.ClientParametersAuthentication)3 VerificationCodeReceiver (com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver)3 LocalServerReceiver (com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver)3 Credential (com.google.api.client.auth.oauth2.Credential)2 AuthorizationCodeInstalledApp (com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp)2 GenericUrl (com.google.api.client.http.GenericUrl)2 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)1 AuthorizationCodeInstalledAppSecureOverride (org.dataportabilityproject.shared.auth.AuthorizationCodeInstalledAppSecureOverride)1