Search in sources :

Example 1 with AuthorizationCodeFlow

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());
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) TokenResponse(com.google.api.client.auth.oauth2.TokenResponse) TokensAndUrlAuthData(org.dataportabilityproject.types.transfer.auth.TokensAndUrlAuthData) IOException(java.io.IOException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow)

Example 2 with AuthorizationCodeFlow

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);
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) TokenResponse(com.google.api.client.auth.oauth2.TokenResponse) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow)

Example 3 with AuthorizationCodeFlow

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);
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) TokenResponse(com.google.api.client.auth.oauth2.TokenResponse) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow)

Example 4 with AuthorizationCodeFlow

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));
}
Also used : ClientParametersAuthentication(com.google.api.client.auth.oauth2.ClientParametersAuthentication) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GenericUrl(com.google.api.client.http.GenericUrl) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow)

Example 5 with AuthorizationCodeFlow

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);
    }
}
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)

Aggregations

AuthorizationCodeFlow (com.google.api.client.auth.oauth2.AuthorizationCodeFlow)12 Credential (com.google.api.client.auth.oauth2.Credential)10 IOException (java.io.IOException)6 TokenResponse (com.google.api.client.auth.oauth2.TokenResponse)5 ClientParametersAuthentication (com.google.api.client.auth.oauth2.ClientParametersAuthentication)4 StoredCredential (com.google.api.client.auth.oauth2.StoredCredential)4 VerificationCodeReceiver (com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver)3 LocalServerReceiver (com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver)3 GenericUrl (com.google.api.client.http.GenericUrl)3 HttpTransport (com.google.api.client.http.HttpTransport)3 ApacheHttpTransport (com.google.api.client.http.apache.v2.ApacheHttpTransport)3 AzureAuthorizationCodeFlow (com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)3 AuthorizationCodeTokenRequest (com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)2 AuthorizationCodeInstalledApp (com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp)2 GoogleAuthorizationCodeFlow (com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 AuthorizationCodeInstalledAppSecureOverride (org.dataportabilityproject.shared.auth.AuthorizationCodeInstalledAppSecureOverride)2 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 AzureHttpRequestCreator (com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator)1