question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

google-oauth-client-jetty incompatible with Jetty 9.4+

See original GitHub issue

Environment details

  1. Specify the API at the beginning of the title - this is generic, related to OAuth and Jetty.
  2. OS type and version: MacOS 10.15.1
  3. Java version: jdk1.8.0_191
  4. google-oauth-client version(s): 1.30.4

Steps to reproduce

  1. Upgrade from 1.30.3 to 1.30.4.
  2. 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
shirishjambhorkarcommented, Apr 15, 2020

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>

2reactions
anton-erofeevcommented, Mar 16, 2020

I downgraded to 1.22.0, it works for me

<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client-jetty</artifactId>
  <version>1.22.0</version>
</dependency>
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found