Class AuthorizationCodeInstalledApp
- java.lang.Object
-
- com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp
-
public class AuthorizationCodeInstalledApp extends java.lang.Object
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
Fields Modifier and Type Field Description private AuthorizationCodeFlow
flow
Authorization code flow.private static java.util.logging.Logger
LOGGER
private VerificationCodeReceiver
receiver
Verification code receiver.
-
Constructor Summary
Constructors Constructor Description AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Credential
authorize(java.lang.String userId)
Authorizes the installed application to access user's protected data.static void
browse(java.lang.String url)
Open a browser at the given URL usingDesktop
if available, or alternatively output the URL toSystem.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.
-
-
-
Field Detail
-
flow
private final AuthorizationCodeFlow flow
Authorization code flow.
-
receiver
private final VerificationCodeReceiver receiver
Verification code receiver.
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
-
Constructor Detail
-
AuthorizationCodeInstalledApp
public AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)
- Parameters:
flow
- authorization code flowreceiver
- verification code receiver
-
-
Method Detail
-
authorize
public Credential authorize(java.lang.String userId) throws java.io.IOException
Authorizes the installed application to access user's protected data.- Parameters:
userId
- user ID ornull
if not using a persisted credential store- Returns:
- credential
- Throws:
java.io.IOException
-
onAuthorization
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws java.io.IOException
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:
java.io.IOException
- I/O exception
-
browse
public static void browse(java.lang.String url)
Open a browser at the given URL usingDesktop
if available, or alternatively output the URL toSystem.out
for command-line applications.- Parameters:
url
- URL to browse
-
getFlow
public final AuthorizationCodeFlow getFlow()
Returns the authorization code flow.
-
getReceiver
public final VerificationCodeReceiver getReceiver()
Returns the verification code receiver.
-
-