use of com.google.ce.media.contentuploader.message.AuthInfo in project gcs-uploader by GoogleCloudPlatform.
the class AuthConfig method updateToken.
public void updateToken(final AuthConfigListener listener) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("x-content-refresh-token", authInfo.getRefreshToken());
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setContentLength(0L);
try {
RequestEntity requestEntity = new RequestEntity(headers, HttpMethod.POST, new URI(envConfig.getAuthEndpoint() + "/auth/renew_access_token"));
ResponseEntity<AuthInfo> authInfoResponse = restTemplate.exchange(requestEntity, AuthInfo.class);
AuthInfo newAuthInfo = authInfoResponse.getBody();
newAuthInfo.setRefreshToken(authInfo.getRefreshToken());
authInfo = newAuthInfo;
credentials = GoogleCredentials.create(new AccessToken(authInfo.getAccessToken(), new Date(authInfo.getExpirationSeconds() * 1000)));
buildStorage();
validateAuthorization();
if (listener != null) {
listener.authInfoUpdated();
}
} catch (Exception e) {
e.printStackTrace();
if (listener != null) {
listener.authInfoError(e);
}
}
}
use of com.google.ce.media.contentuploader.message.AuthInfo in project gcs-uploader by GoogleCloudPlatform.
the class TokenController method swapCode.
@RequestMapping(value = "/swap", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<UserInfo> swapCode(@RequestHeader(value = "x-content-upload-offline-code") String offlineCode, @RequestHeader(value = "host") String host, HttpServletRequest request) throws URISyntaxException {
AuthInfo authInfo = authConfig.swapToken(offlineCode, host);
uiMasterController.validateAuthorization();
UserInfo userInfo = new UserInfo();
userInfo.setPictureUrl(authInfo.getPictureUrl());
userInfo.setEmail(authInfo.getEmail());
userInfo.setUserId(authInfo.getUserId());
userInfo.setName(authInfo.getName());
AnalyticsMessage m1 = AnalyticsMessage.from(authInfo, AnalyticsMessage.Event.LOGIN, "Login");
AnalyticsService.getInstance().enqueue(authInfo, m1);
return new ResponseEntity<>(userInfo, HttpStatus.OK);
}
use of com.google.ce.media.contentuploader.message.AuthInfo in project gcs-uploader by GoogleCloudPlatform.
the class AuthConfig method swapToken.
public AuthInfo swapToken(String offlineCode, String host) throws URISyntaxException {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("x-content-upload-offline-code", offlineCode);
headers.add("x-content-upload-host", host);
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setContentLength(0L);
RequestEntity requestEntity = new RequestEntity(headers, HttpMethod.POST, new URI(envConfig.getAuthEndpoint() + "/auth/offline_info"));
ResponseEntity<AuthInfo> authInfoResponse = restTemplate.exchange(requestEntity, AuthInfo.class);
authInfo = authInfoResponse.getBody();
credentials = GoogleCredentials.create(new AccessToken(authInfo.getAccessToken(), new Date(authInfo.getExpirationSeconds() * 1000)));
buildStorage();
validateAuthorization();
return authInfo;
}
Aggregations