Search in sources :

Example 1 with AuthorizationCodeInstalledAppSecureOverride

use of org.dataportabilityproject.shared.auth.AuthorizationCodeInstalledAppSecureOverride 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)

Aggregations

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