Class AuthorizationCodeInstalledApp
java.lang.Object
com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp
OAuth 2.0 authorization code flow for an installed Java application that persists end-user
credentials.
Implementation is thread-safe.
- Since:
- 1.11
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AuthorizationCodeFlowAuthorization code flow.private static final Loggerprivate final VerificationCodeReceiverVerification code receiver. -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionAuthorizes the installed application to access user's protected data.static voidOpen a browser at the given URL usingDesktopif available, or alternatively output the URL toSystem.outfor command-line applications.final AuthorizationCodeFlowgetFlow()Returns the authorization code flow.final VerificationCodeReceiverReturns the verification code receiver.protected voidonAuthorization(AuthorizationCodeRequestUrl authorizationUrl) Handles user authorization by redirecting to the OAuth 2.0 authorization server.
-
Field Details
-
flow
Authorization code flow. -
receiver
Verification code receiver. -
LOGGER
-
-
Constructor Details
-
AuthorizationCodeInstalledApp
- Parameters:
flow- authorization code flowreceiver- verification code receiver
-
-
Method Details
-
authorize
Authorizes the installed application to access user's protected data.- Parameters:
userId- user ID ornullif not using a persisted credential store- Returns:
- credential
- Throws:
IOException
-
onAuthorization
Handles user authorization by redirecting to the OAuth 2.0 authorization server.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); }- Parameters:
authorizationUrl- authorization URL- Throws:
IOException- I/O exception
-
browse
Open a browser at the given URL usingDesktopif available, or alternatively output the URL toSystem.outfor command-line applications.- Parameters:
url- URL to browse
-
getFlow
Returns the authorization code flow. -
getReceiver
Returns the verification code receiver.
-