or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# Google OAuth Client Java 6

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: google-oauth-client-java6

7

- **Package Type**: maven

8

- **Language**: Java

9

- **Group ID**: com.google.oauth-client

10

- **Artifact ID**: google-oauth-client-java6

11

- **Installation**:

12

```xml

13

<dependency>

14

<groupId>com.google.oauth-client</groupId>

15

<artifactId>google-oauth-client-java6</artifactId>

16

<version>1.39.0</version>

17

</dependency>

18

```

19

20

## Core Imports

21

22

```java

23

import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;

24

import com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver;

25

import com.google.api.client.extensions.java6.auth.oauth2.AbstractPromptReceiver;

26

import com.google.api.client.extensions.java6.auth.oauth2.FileCredentialStore;

27

import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;

28

import com.google.api.client.auth.oauth2.Credential;

29

```

30

31

## Basic Usage

32

33

```java

34

import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;

35

import com.google.api.client.auth.oauth2.BearerToken;

36

import com.google.api.client.auth.oauth2.Credential;

37

import com.google.api.client.auth.oauth2.ClientParametersAuthentication;

38

import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;

39

import com.google.api.client.extensions.java6.auth.oauth2.AbstractPromptReceiver;

40

import com.google.api.client.http.HttpTransport;

41

import com.google.api.client.http.GenericUrl;

42

import com.google.api.client.json.JsonFactory;

43

44

// Create a custom prompt receiver

45

class ConsoleReceiver extends AbstractPromptReceiver {

46

@Override

47

public String getRedirectUri() {

48

return "urn:ietf:wg:oauth:2.0:oob";

49

}

50

}

51

52

// Set up OAuth flow for installed application

53

AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(

54

BearerToken.authorizationHeaderAccessMethod(),

55

httpTransport, // Your HttpTransport instance

56

jsonFactory, // Your JsonFactory instance

57

new GenericUrl("https://oauth2.googleapis.com/token"), // Token server URL

58

new ClientParametersAuthentication("your-client-id", "your-client-secret"), // Client authentication

59

"your-client-id", // Your OAuth 2.0 client ID

60

"https://accounts.google.com/o/oauth2/auth") // Authorization server URL

61

.build();

62

63

// Authorize user

64

ConsoleReceiver receiver = new ConsoleReceiver();

65

AuthorizationCodeInstalledApp app = new AuthorizationCodeInstalledApp(flow, receiver);

66

Credential credential = app.authorize("user123");

67

```

68

69

## Architecture

70

71

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

72

73

- **Verification Code Receivers**: Interface and implementations for receiving OAuth 2.0 verification codes

74

- **Authorization Flow Integration**: Seamless integration with Google OAuth Client's authorization flows

75

- **Credential Persistence**: File-based credential storage for maintaining tokens across application restarts (deprecated components)

76

- **Browser Integration**: Automatic browser launching with fallback to manual URL copy-paste

77

78

## Capabilities

79

80

### Authorization Code Flow for Installed Apps

81

82

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

83

84

```java { .api }

85

public class AuthorizationCodeInstalledApp {

86

public AuthorizationCodeInstalledApp(

87

AuthorizationCodeFlow flow,

88

VerificationCodeReceiver receiver);

89

90

public AuthorizationCodeInstalledApp(

91

AuthorizationCodeFlow flow,

92

VerificationCodeReceiver receiver,

93

Browser browser);

94

95

public Credential authorize(String userId) throws IOException;

96

97

public final AuthorizationCodeFlow getFlow();

98

99

public final VerificationCodeReceiver getReceiver();

100

101

public static void browse(String url);

102

}

103

```

104

105

[Authorization Code Flow](./authorization-flow.md)

106

107

### Verification Code Receivers

108

109

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

110

111

```java { .api }

112

public interface VerificationCodeReceiver {

113

String getRedirectUri() throws IOException;

114

String waitForCode() throws IOException;

115

void stop() throws IOException;

116

}

117

118

public abstract class AbstractPromptReceiver implements VerificationCodeReceiver {

119

public String waitForCode();

120

public void stop();

121

public abstract String getRedirectUri() throws IOException;

122

}

123

124

// Browser interface for custom browser implementations

125

public static interface Browser {

126

public void browse(String url) throws IOException;

127

}

128

129

public static class DefaultBrowser implements Browser {

130

@Override

131

public void browse(String url) throws IOException;

132

}

133

```

134

135

[Verification Code Receivers](./verification-receivers.md)

136

137

### File-Based Credential Storage (Deprecated)

138

139

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

140

141

```java { .api }

142

@Deprecated

143

public class FileCredentialStore implements CredentialStore {

144

public FileCredentialStore(File file, JsonFactory jsonFactory) throws IOException;

145

public void store(String userId, Credential credential) throws IOException;

146

public boolean load(String userId, Credential credential);

147

public void delete(String userId, Credential credential) throws IOException;

148

}

149

```

150

151

[File Credential Storage](./file-credential-storage.md)

152

153

## Migration Notes

154

155

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

156

157

```java

158

// Deprecated approach

159

FileCredentialStore store = new FileCredentialStore(file, jsonFactory);

160

161

// Recommended approach

162

FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(dataDirectory);

163

DataStore<StoredCredential> dataStore = StoredCredential.getDefaultDataStore(dataStoreFactory);

164

```