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