or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authorization-flow.mdfile-credential-storage.mdindex.mdverification-receivers.md
tile.json

tessl/maven-com-google-oauth-client--google-oauth-client-java6

Java 6+ extensions to the Google OAuth Client Library providing verification code receivers and credential persistence for OAuth 2.0 flows

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.google.oauth-client/google-oauth-client-java6@1.39.x

To install, run

npx @tessl/cli install tessl/maven-com-google-oauth-client--google-oauth-client-java6@1.39.0

index.mddocs/

Google OAuth Client Java 6

Google OAuth Client Java 6 provides Java 6+ extensions to the Google OAuth Client Library for Java. It focuses on OAuth 2.0 verification code receivers and credential persistence mechanisms for installed applications, command-line tools, and desktop applications that need to handle OAuth 2.0 authorization flows.

Package Information

  • Package Name: google-oauth-client-java6
  • Package Type: maven
  • Language: Java
  • Group ID: com.google.oauth-client
  • Artifact ID: google-oauth-client-java6
  • Installation:
    <dependency>
      <groupId>com.google.oauth-client</groupId>
      <artifactId>google-oauth-client-java6</artifactId>
      <version>1.39.0</version>
    </dependency>

Core Imports

import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver;
import com.google.api.client.extensions.java6.auth.oauth2.AbstractPromptReceiver;
import com.google.api.client.extensions.java6.auth.oauth2.FileCredentialStore;
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;
import com.google.api.client.auth.oauth2.Credential;

Basic Usage

import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;
import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.auth.oauth2.ClientParametersAuthentication;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.java6.auth.oauth2.AbstractPromptReceiver;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.json.JsonFactory;

// Create a custom prompt receiver
class ConsoleReceiver extends AbstractPromptReceiver {
    @Override
    public String getRedirectUri() {
        return "urn:ietf:wg:oauth:2.0:oob";
    }
}

// Set up OAuth flow for installed application
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(
    BearerToken.authorizationHeaderAccessMethod(),
    httpTransport,      // Your HttpTransport instance
    jsonFactory,        // Your JsonFactory instance  
    new GenericUrl("https://oauth2.googleapis.com/token"), // Token server URL
    new ClientParametersAuthentication("your-client-id", "your-client-secret"), // Client authentication
    "your-client-id",   // Your OAuth 2.0 client ID
    "https://accounts.google.com/o/oauth2/auth") // Authorization server URL
    .build();

// Authorize user
ConsoleReceiver receiver = new ConsoleReceiver();
AuthorizationCodeInstalledApp app = new AuthorizationCodeInstalledApp(flow, receiver);
Credential credential = app.authorize("user123");

Architecture

Google OAuth Client Java 6 is built around several key components:

  • Verification Code Receivers: Interface and implementations for receiving OAuth 2.0 verification codes
  • Authorization Flow Integration: Seamless integration with Google OAuth Client's authorization flows
  • Credential Persistence: File-based credential storage for maintaining tokens across application restarts (deprecated components)
  • Browser Integration: Automatic browser launching with fallback to manual URL copy-paste

Capabilities

Authorization Code Flow for Installed Apps

Complete OAuth 2.0 authorization flow implementation for installed applications, including browser integration and credential management.

public class AuthorizationCodeInstalledApp {
    public AuthorizationCodeInstalledApp(
        AuthorizationCodeFlow flow, 
        VerificationCodeReceiver receiver);
    
    public AuthorizationCodeInstalledApp(
        AuthorizationCodeFlow flow, 
        VerificationCodeReceiver receiver, 
        Browser browser);
    
    public Credential authorize(String userId) throws IOException;
    
    public final AuthorizationCodeFlow getFlow();
    
    public final VerificationCodeReceiver getReceiver();
    
    public static void browse(String url);
}

Authorization Code Flow

Verification Code Receivers

Interface and implementations for receiving OAuth 2.0 verification codes from users during the authorization process.

public interface VerificationCodeReceiver {
    String getRedirectUri() throws IOException;
    String waitForCode() throws IOException;
    void stop() throws IOException;
}

public abstract class AbstractPromptReceiver implements VerificationCodeReceiver {
    public String waitForCode();
    public void stop();
    public abstract String getRedirectUri() throws IOException;
}

// Browser interface for custom browser implementations
public static interface Browser {
    public void browse(String url) throws IOException;
}

public static class DefaultBrowser implements Browser {
    @Override
    public void browse(String url) throws IOException;
}

Verification Code Receivers

File-Based Credential Storage (Deprecated)

Legacy file-based credential storage system for persisting OAuth 2.0 credentials. These components are deprecated in favor of FileDataStoreFactory.

@Deprecated
public class FileCredentialStore implements CredentialStore {
    public FileCredentialStore(File file, JsonFactory jsonFactory) throws IOException;
    public void store(String userId, Credential credential) throws IOException;
    public boolean load(String userId, Credential credential);
    public void delete(String userId, Credential credential) throws IOException;
}

File Credential Storage

Migration Notes

The file-based credential storage classes (FileCredentialStore, FilePersistedCredential, FilePersistedCredentials) are deprecated. Use FileDataStoreFactory with StoredCredential instead:

// Deprecated approach
FileCredentialStore store = new FileCredentialStore(file, jsonFactory);

// Recommended approach  
FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(dataDirectory);
DataStore<StoredCredential> dataStore = StoredCredential.getDefaultDataStore(dataStoreFactory);