public class AuthorizationCodeInstalledApp extends Object
Implementation is thread-safe.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AuthorizationCodeInstalledApp.Browser
Helper interface to allow caller to browse.
|
static class |
AuthorizationCodeInstalledApp.DefaultBrowser
Default browser that just delegates to
browse(String). |
| Constructor and Description |
|---|
AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow,
VerificationCodeReceiver receiver) |
AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow,
VerificationCodeReceiver receiver,
AuthorizationCodeInstalledApp.Browser browser) |
| 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 AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver, AuthorizationCodeInstalledApp.Browser browser)
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–2022 Google. All rights reserved.