/** * Use the {@link Credential} to request a new access token from the * authorization endpoint. * * @return whether a new access token was successfully retrieved */ public boolean refreshToken() throws AuthenticationException { try { return this.credential.refreshToken(); } catch (IOException e) { AuthenticationException ae = new AuthenticationException("Failed to refresh access token: " + e.getMessage()); ae.initCause(e); throw ae; } } }
/** * Encapsulates the OAuth information used by applications to login on behalf * of a user. This class generates an unique authorization header for each * request. */ public static class OAuthToken implements HttpAuthToken { OAuthParameters parameters; GoogleOAuthHelper oauthHelper; /** * Create a new {@link OAuthToken} object. Store the * {@link OAuthParameters} and {@link OAuthSigner} to use when generating * the header. The following OAuth parameters are required: * <ul> * <li>oauth_consumer_key * <li>oauth_token * </ul> * * @param parameters the required OAuth parameters * @param signer the {@link OAuthSigner} object to use when to generate the * OAuth signature. */ public OAuthToken(OAuthParameters parameters, OAuthSigner signer) { this.parameters = parameters; oauthHelper = new GoogleOAuthHelper(signer); } /** * Generates the OAuth authorization header using the user's OAuth
/** * Encapsulates the OAuth 2.0 information used by applications to login on * behalf of a user. */ public static class OAuth2Token implements HttpAuthToken { static final String HEADER_PREFIX = "Bearer "; final Credential credential; /** * Create a new {@link OAuth2Token} object. Store the {@link Credential} to * use when generating the header. * * @param credential the required OAuth 2.0 credentials */ public OAuth2Token(Credential credential) { this.credential = credential; } /** * Returns the authorization header using the user's OAuth 2.0 credentials. * * @param requestUrl the URL being requested * @param requestMethod the HTTP method of the request * @return the authorization header to be used for the request */ public String getAuthorizationHeader(URL requestUrl, String requestMethod) { return HEADER_PREFIX + this.credential.getAccessToken(); }
/** * Encapsulates the OAuth information used by applications to login on behalf * of a user. This class generates an unique authorization header for each * request. */ public static class OAuthToken implements HttpAuthToken { OAuthParameters parameters; final OAuthSigner signer; /** * Create a new {@link OAuthToken} object. Store the * {@link OAuthParameters} and {@link OAuthSigner} to use when generating * the header. The following OAuth parameters are required: * <ul> * <li>oauth_consumer_key * <li>oauth_token * </ul> * * @param parameters the required OAuth parameters * @param signer the {@link OAuthSigner} object to use when to generate the * OAuth signature. */ public OAuthToken(OAuthParameters parameters, OAuthSigner signer) { this.parameters = parameters; this.signer = signer; } /** * Generates the OAuth authorization header using the user's OAuth