Class AuthorizationCodeInstalledApp (1.34.1)

public class AuthorizationCodeInstalledApp

OAuth 2.0 authorization code flow for an installed Java application that persists end-user credentials.

Implementation is thread-safe.

Inheritance

java.lang.Object > AuthorizationCodeInstalledApp

Static Methods

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.

Parameter
Name Description
url String

URL to browse

Constructors

AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)

public AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)
Parameters
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)
Parameters
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.

Parameter
Name Description
userId String

user ID or null if not using a persisted credential store

Returns
Type Description
Credential

credential

Exceptions
Type Description
IOException

getFlow()

public final AuthorizationCodeFlow getFlow()

Returns the authorization code flow.

Returns
Type Description
AuthorizationCodeFlow

getReceiver()

public final VerificationCodeReceiver getReceiver()

Returns the verification code receiver.

Returns
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); }

Parameter
Name Description
authorizationUrl AuthorizationCodeRequestUrl

authorization URL

Exceptions
Type Description
IOException

I/O exception