public class AuthorizationCodeInstalledApp
OAuth 2.0 authorization code flow for an installed Java application that persists end-user credentials.
Implementation is thread-safe.
Constructors
AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)
public AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)
Name | Description |
flow | AuthorizationCodeFlow authorization code flow |
receiver | VerificationCodeReceiver verification code receiver |
AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver, AuthorizationCodeInstalledApp.Browser browser)
public AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver, AuthorizationCodeInstalledApp.Browser browser)
Name | Description |
flow | AuthorizationCodeFlow authorization code flow |
receiver | VerificationCodeReceiver verification code receiver |
browser | AuthorizationCodeInstalledApp.Browser |
Methods
authorize(String userId)
public Credential authorize(String userId)
Authorizes the installed application to access user's protected data.
Name | Description |
userId | String user ID or |
Type | Description |
Credential | credential |
Type | Description |
IOException |
browse(String url)
public 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.
Name | Description |
url | String URL to browse |
getFlow()
public final AuthorizationCodeFlow getFlow()
Returns the authorization code flow.
Type | Description |
AuthorizationCodeFlow |
getReceiver()
public final VerificationCodeReceiver getReceiver()
Returns the verification code receiver.
Type | Description |
VerificationCodeReceiver |
onAuthorization(AuthorizationCodeRequestUrl authorizationUrl)
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl)
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); }
Name | Description |
authorizationUrl | AuthorizationCodeRequestUrl authorization URL |
Type | Description |
IOException | I/O exception |