Class AuthorizationCodeInstalledApp (1.32.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

Constructors

AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)

public AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver)
Parameters
NameDescription
flowAuthorizationCodeFlow

authorization code flow

receiverVerificationCodeReceiver

verification code receiver

AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver, AuthorizationCodeInstalledApp.Browser browser)

public AuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver, AuthorizationCodeInstalledApp.Browser browser)
Parameters
NameDescription
flowAuthorizationCodeFlow

authorization code flow

receiverVerificationCodeReceiver

verification code receiver

browserAuthorizationCodeInstalledApp.Browser

Methods

authorize(String userId)

public Credential authorize(String userId)

Authorizes the installed application to access user's protected data.

Parameter
NameDescription
userIdString

user ID or null if not using a persisted credential store

Returns
TypeDescription
Credential

credential

Exceptions
TypeDescription
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.

Parameter
NameDescription
urlString

URL to browse

getFlow()

public final AuthorizationCodeFlow getFlow()

Returns the authorization code flow.

Returns
TypeDescription
AuthorizationCodeFlow

getReceiver()

public final VerificationCodeReceiver getReceiver()

Returns the verification code receiver.

Returns
TypeDescription
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
NameDescription
authorizationUrlAuthorizationCodeRequestUrl

authorization URL

Exceptions
TypeDescription
IOException

I/O exception