use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse 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());
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse 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);
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse 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);
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project repairnator by Spirals-Team.
the class ManageGoogleAccessToken method initializeCredentialFromAccessToken.
public void initializeCredentialFromAccessToken(String accessToken) {
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setAccessToken(accessToken);
tokenResponse.setTokenType("offline");
this.credential = new GoogleCredential().setFromTokenResponse(tokenResponse);
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project workbench by all-of-us.
the class DelegatedUserCredentials method refreshAccessToken.
@Override
public AccessToken refreshAccessToken() throws IOException {
// The first step is to call the IamCredentials API to generate a signed JWT with the
// appropriate claims. This call is authorized with application default credentials (ADCs). The
// ADC service account may be different from `serviceAccountEmail` if the ADC account has the
// roles/iam.serviceAccountTokenCreator role on the `serviceAccountEmail` account.
SignJwtRequest jwtRequest = SignJwtRequest.newBuilder().setName(String.format(SERVICE_ACCOUNT_NAME_FORMAT, serviceAccountEmail)).setPayload(JSON_FACTORY.toString(createJwtPayload())).build();
String jwt = credentialsClient.signJwt(jwtRequest).getSignedJwt();
// With the signed JWT in hand, we call Google's OAuth2 token server to exchange the JWT for
// an access token.
TokenRequest tokenRequest = new TokenRequest(httpTransport, JSON_FACTORY, new GenericUrl(GoogleOAuthConstants.TOKEN_SERVER_URL), JWT_BEARER_GRANT_TYPE);
tokenRequest.put("assertion", jwt);
TokenResponse tokenResponse = tokenRequest.execute();
return new AccessToken(tokenResponse.getAccessToken(), Date.from(Instant.now(clock).plusSeconds(tokenResponse.getExpiresInSeconds())));
}
Aggregations