use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project data-transfer-project by google.
the class MicrosoftAuth 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 MS oauth flow");
Preconditions.checkArgument(initialAuthData == null, "Earlier auth data not expected for MS 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());
// GoogleIdToken.Payload payload = ((GoogleTokenResponse) response).parseIdToken().getPayload();
return toAuthData(credential);
}
use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow 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.auth.oauth2.AuthorizationCodeFlow in project hub-alert by blackducksoftware.
the class AzureBoardsProperties method hasOAuthCredentials.
public boolean hasOAuthCredentials(ProxyInfo proxy) {
HttpTransport httpTransport = createHttpTransport(proxy);
try {
AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
Optional<Credential> oAuthCredential = getExistingOAuthCredential(oAuthFlow);
return oAuthCredential.isPresent();
} catch (IOException e) {
return false;
}
}
use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project hub-alert by blackducksoftware.
the class AzureBoardsProperties method requestTokens.
public Optional<Credential> requestTokens(AuthorizationCodeFlow authorizationCodeFlow, String authorizationCode) throws IOException {
AuthorizationCodeTokenRequest tokenRequest = authorizationCodeFlow.newTokenRequest(authorizationCode);
TokenResponse tokenResponse = tokenRequest.execute();
Credential credential = authorizationCodeFlow.createAndStoreCredential(tokenResponse, oauthUserId);
return Optional.ofNullable(credential);
}
use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project hub-alert by blackducksoftware.
the class AzureBoardsProperties method createAzureHttpRequestCreator.
public AzureHttpRequestCreator createAzureHttpRequestCreator(ProxyInfo proxyInfo, Gson gson) throws AlertException {
HttpTransport httpTransport = createHttpTransport(proxyInfo);
try {
AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
Credential oAuthCredential = getExistingOAuthCredential(oAuthFlow).orElseThrow(() -> new AlertException(String.format("No existing Azure OAuth credential associated with '%s'", oauthUserId)));
return AzureHttpRequestCreatorFactory.withCredential(httpTransport, oAuthCredential, gson);
} catch (IOException e) {
throw new AlertException("Cannot read OAuth credentials", e);
}
}
Aggregations