public class AuthorizationCodeInstalledApp extends Object
Implementation is thread-safe.
| Constructor and Description |
|---|
AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow,
VerificationCodeReceiver receiver) |
| Modifier and Type | Method and Description |
|---|---|
Credential |
authorize(String userId)
Authorizes the installed application to access user's protected data.
|
static void |
browse(String url)
Open a browser at the given URL using
Desktop if available, or alternatively output the
URL to System.out for command-line applications. |
AuthorizationCodeFlow |
getFlow()
Returns the authorization code flow.
|
VerificationCodeReceiver |
getReceiver()
Returns the verification code receiver.
|
protected void |
onAuthorization(AuthorizationCodeRequestUrl authorizationUrl)
Handles user authorization by redirecting to the OAuth 2.0 authorization server.
|
public AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)
flow - authorization code flowreceiver - verification code receiverpublic Credential authorize(String userId) throws IOException
userId - user ID or null if not using a persisted credential storeIOExceptionprotected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException
Default implementation is to call browse(authorizationUrl.build()). Subclasses may
override to provide optional parameters such as the recommended state parameter. Sample
implementation:
@Override
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException {
authorizationUrl.setState("xyz");
super.onAuthorization(authorizationUrl);
}
authorizationUrl - authorization URLIOException - I/O exceptionpublic static void browse(String url)
Desktop if available, or alternatively output the
URL to System.out for command-line applications.url - URL to browsepublic final AuthorizationCodeFlow getFlow()
public final VerificationCodeReceiver getReceiver()
Copyright © 2011-2017 Google. All Rights Reserved.