use of com.google.api.client.auth.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.google.api.client.auth.oauth2.TokenResponse in project google-api-java-client by google.
the class GoogleCredential method executeRefreshToken.
@Override
@Beta
protected TokenResponse executeRefreshToken() throws IOException {
if (serviceAccountPrivateKey == null) {
return super.executeRefreshToken();
}
// service accounts: no refresh token; instead use private key to request new access token
JsonWebSignature.Header header = new JsonWebSignature.Header();
header.setAlgorithm("RS256");
header.setType("JWT");
header.setKeyId(serviceAccountPrivateKeyId);
JsonWebToken.Payload payload = new JsonWebToken.Payload();
long currentTime = getClock().currentTimeMillis();
payload.setIssuer(serviceAccountId);
payload.setAudience(getTokenServerEncodedUrl());
payload.setIssuedAtTimeSeconds(currentTime / 1000);
payload.setExpirationTimeSeconds(currentTime / 1000 + 3600);
payload.setSubject(serviceAccountUser);
payload.put("scope", Joiner.on(' ').join(serviceAccountScopes));
try {
String assertion = JsonWebSignature.signUsingRsaSha256(serviceAccountPrivateKey, getJsonFactory(), header, payload);
TokenRequest request = new TokenRequest(getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()), "urn:ietf:params:oauth:grant-type:jwt-bearer");
request.put("assertion", assertion);
return request.execute();
} catch (GeneralSecurityException exception) {
IOException e = new IOException();
e.initCause(exception);
throw e;
}
}
use of com.google.api.client.auth.oauth2.TokenResponse in project google-api-java-client by google.
the class CloudShellCredential method executeRefreshToken.
@Override
protected TokenResponse executeRefreshToken() throws IOException {
Socket socket = new Socket("localhost", this.getAuthPort());
socket.setSoTimeout(READ_TIMEOUT_MS);
TokenResponse token = new TokenResponse();
try {
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println(GET_AUTH_TOKEN_REQUEST);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
// Ignore the size line
input.readLine();
Collection<Object> messageArray = jsonFactory.createJsonParser(input).parseArray(LinkedList.class, Object.class);
String accessToken = ((List<Object>) messageArray).get(ACCESS_TOKEN_INDEX).toString();
token.setAccessToken(accessToken);
} finally {
socket.close();
}
return token;
}
use of com.google.api.client.auth.oauth2.TokenResponse in project fess by codelibs.
the class OpenIdConnectAuthenticator method processCallback.
protected LoginCredential processCallback(final HttpServletRequest request, final String code) {
try {
final TokenResponse tr = getTokenUrl(code);
final String[] jwt = ((String) tr.get("id_token")).split("\\.");
final String jwtHeader = new String(Base64.decodeBase64(jwt[0]), Constants.UTF_8_CHARSET);
final String jwtClaim = new String(Base64.decodeBase64(jwt[1]), Constants.UTF_8_CHARSET);
final String jwtSigniture = new String(Base64.decodeBase64(jwt[2]), Constants.UTF_8_CHARSET);
if (logger.isDebugEnabled()) {
logger.debug("jwtHeader: {}", jwtHeader);
logger.debug("jwtClaim: {}", jwtClaim);
logger.debug("jwtSigniture: {}", jwtSigniture);
}
// TODO validate signiture
final Map<String, Object> attributes = new HashMap<>();
attributes.put("accesstoken", tr.getAccessToken());
attributes.put("refreshtoken", tr.getRefreshToken() == null ? "null" : tr.getRefreshToken());
attributes.put("tokentype", tr.getTokenType());
attributes.put("expire", tr.getExpiresInSeconds());
attributes.put("jwtheader", jwtHeader);
attributes.put("jwtclaim", jwtClaim);
attributes.put("jwtsign", jwtSigniture);
if (logger.isDebugEnabled()) {
logger.debug("attribute: {}", attributes);
}
parseJwtClaim(jwtClaim, attributes);
return new OpenIdConnectCredential(attributes);
} catch (final IOException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to process callbacked request.", e);
}
}
return null;
}
use of com.google.api.client.auth.oauth2.TokenResponse 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);
}
Aggregations