Search in sources :

Example 1 with AuthInfo

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);
        }
    }
}
Also used : AuthInfo(com.google.ce.media.contentuploader.message.AuthInfo) AccessToken(com.google.auth.oauth2.AccessToken) RestTemplate(org.springframework.web.client.RestTemplate) URI(java.net.URI) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) StorageException(com.google.cloud.storage.StorageException)

Example 2 with AuthInfo

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);
}
Also used : AuthInfo(com.google.ce.media.contentuploader.message.AuthInfo) ResponseEntity(org.springframework.http.ResponseEntity) UserInfo(com.google.ce.media.contentuploader.message.UserInfo) AnalyticsMessage(com.google.ce.media.contentuploader.message.AnalyticsMessage)

Example 3 with AuthInfo

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;
}
Also used : AuthInfo(com.google.ce.media.contentuploader.message.AuthInfo) AccessToken(com.google.auth.oauth2.AccessToken) RestTemplate(org.springframework.web.client.RestTemplate) URI(java.net.URI) Date(java.util.Date)

Aggregations

AuthInfo (com.google.ce.media.contentuploader.message.AuthInfo)3 AccessToken (com.google.auth.oauth2.AccessToken)2 URI (java.net.URI)2 Date (java.util.Date)2 RestTemplate (org.springframework.web.client.RestTemplate)2 AnalyticsMessage (com.google.ce.media.contentuploader.message.AnalyticsMessage)1 UserInfo (com.google.ce.media.contentuploader.message.UserInfo)1 StorageException (com.google.cloud.storage.StorageException)1 URISyntaxException (java.net.URISyntaxException)1 ResponseEntity (org.springframework.http.ResponseEntity)1