google-oauth-client-jetty incompatible with Jetty 9.4+
See original GitHub issueEnvironment details
- Specify the API at the beginning of the title - this is generic, related to OAuth and Jetty.
- OS type and version: MacOS 10.15.1
- Java version: jdk1.8.0_191
- google-oauth-client version(s): 1.30.4
Steps to reproduce
- Upgrade from 1.30.3 to 1.30.4.
- Run the code below - GoogleCredentialHelper.getInstance(someScopes).authorize();
Code example
private static final String CREDENTIAL_FILEPATH = "/credentials/credentials.json";
private static final java.io.File DATA_STORE_DIR = new java.io.File(
System.getProperty("user.home"), ".credentials/template");
private FileDataStoreFactory dataStoreFactory;
private final JsonFactory jsonFactory;
private HttpTransport httpTransport;
private List<String> scopes;
private GoogleCredentialHelper(List<String> scopes) {
this.jsonFactory = JacksonFactory.getDefaultInstance();
try {
this.httpTransport = GoogleNetHttpTransport.newTrustedTransport();
this.dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
this.scopes = scopes;
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
private Credential authorize() throws IOException {
InputStream in = GoogleCredentialHelper.class.getResourceAsStream(CREDENTIAL_FILEPATH);
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
jsonFactory, new InputStreamReader(in)
);
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, clientSecrets, scopes)
.setDataStoreFactory(dataStoreFactory)
.setAccessType("offline")
.build();
Credential credential = new AuthorizationCodeInstalledApp(
flow, new LocalServerReceiver()).authorize("user");
return credential;
}
public static GoogleCredentialHelper getInstance(List<String> scopes) {
if (instance == null) {
instance = new GoogleCredentialHelper(scopes);
}
return instance;
}
Stack trace
java.lang.NoSuchMethodError: org.eclipse.jetty.server.Connector.setHost(Ljava/lang/String;)V
at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:120)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:121)
at com.project.gapps.GoogleCredentialHelper.authorize(GoogleCredentialHelper.java:68)
Any additional information below
The issue appeared after upgrading from 1.30.3 to 1.30.4. Most likely related to the upgrade of Jetty to 8.2 in the latest version.
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.30.4</version>
</dependency>
The exception appears when credentials are not saved yet - user has to grant permissions via browser.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:14 (4 by maintainers)
Top Results From Across the Web
google-oauth-client-jetty cannot run on Tomcat 7
Seems there is a conflict of servlet-api . To avoid this you should exclude servlet-api from jetty dependency. On Maven:
Read more >Jetty : The Definitive Reference - Eclipse
It explains how to use Jetty to deploy web applications, configure contexts and connects, and how to implement SSL and other security measures....
Read more >Jetty: VERSION.txt - Fossies
1 jetty-9.4.49.v20220914 - 14 September 2022 2 + 8414 BlockingArrayQueue drops all contents on drain 3 + 8493 Review HTTP client feature ...
Read more >Confluence Mobile - Perspectium Documentation
The following is a list of all the third party libraries used by Perspectium meshlets to support their core functionality. These third party...
Read more >Salesforce Connector Release Notes - Mule 4
If you delete the running app's OAuth access token from Salesforce Session Management, ... Jetty Client org.eclipse.jetty:jetty-client:9.4.39.v20210325 to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Google has fixed the issue in latest jars. 1.30.6 is working for me.
<dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client-jetty</artifactId> <version>1.30.6</version> </dependency>I downgraded to 1.22.0, it works for me