LEFT | RIGHT |
(no file at all) | |
| 1 /* |
| 2 * Copyright (c) 2012 Google Inc. |
| 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * |
| 7 * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. |
| 13 */ |
| 14 |
| 15 package com.google.api.client.extensions.java6.auth.oauth2; |
| 16 |
| 17 import com.google.api.client.auth.oauth2.Credential; |
| 18 import com.google.api.client.json.GenericJson; |
| 19 import com.google.api.client.util.Key; |
| 20 |
| 21 /** |
| 22 * Persisted credential implementation to be used exclusively with |
| 23 * {@link FileCredentialStore}. |
| 24 *· |
| 25 * @author Rafael Naufal |
| 26 * @since 1.11 |
| 27 */ |
| 28 public class FilePersistedCredential extends GenericJson { |
| 29 |
| 30 /** Access token or {@code null} for none. */ |
| 31 @Key("access_token") |
| 32 private String accessToken; |
| 33 |
| 34 /** Refresh token {@code null} for none. */ |
| 35 @Key("refresh_token") |
| 36 private String refreshToken; |
| 37 |
| 38 /** Expiration time in milliseconds {@code null} for none. */ |
| 39 @Key("expiration_time_millis") |
| 40 private Long expirationTimeMillis; |
| 41 |
| 42 /** |
| 43 * Store information from the credential. |
| 44 *· |
| 45 * @param userId |
| 46 * user ID whose credential needs to be stored |
| 47 * @param credential |
| 48 * credential whose {@link Credential#getAccessToken access token}, |
| 49 * {@link Credential#getRefreshToken refresh token}, and |
| 50 * {@link Credential#getExpirationTimeMilliseconds expiration time} |
| 51 * need to be stored |
| 52 */ |
| 53 void store(String userId, Credential credential) { |
| 54 this.accessToken = credential.getAccessToken(); |
| 55 this.refreshToken = credential.getRefreshToken(); |
| 56 this.expirationTimeMillis = credential.getExpirationTimeMilliseconds(); |
| 57 } |
| 58 |
| 59 /** |
| 60 * @param credential |
| 61 * credential whose {@link Credential#setAccessToken access token}, |
| 62 * {@link Credential#setRefreshToken refresh token}, and |
| 63 * {@link Credential#setExpirationTimeMilliseconds expiration time} |
| 64 * need to be set if the credential already exists in storage |
| 65 */ |
| 66 void load(String userId, Credential credential) { |
| 67 credential.setAccessToken(this.accessToken); |
| 68 credential.setRefreshToken(this.refreshToken); |
| 69 credential.setExpirationTimeMilliseconds(this.expirationTimeMillis); |
| 70 } |
| 71 } |
LEFT | RIGHT |