Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lagivan opened this issue Nov 18, 2019 · 14 comments · Fixed by #433
Closed

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

lagivan opened this issue Nov 18, 2019 · 14 comments · Fixed by #433
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@lagivan
Copy link

lagivan commented Nov 18, 2019

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.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Nov 19, 2019
@knoppixmeister
Copy link

knoppixmeister commented Dec 2, 2019

using of LocalServerReceiver.Builder class instead of "plain" new LocalServerReceiver object could be like workaround

Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver.Builder().setPort(8082).build()).authorize("user");

@Ancient123
Copy link

@lagivan : Sorry for breaking things 😞

@codyoss codyoss added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Dec 6, 2019
@ncaq
Copy link

ncaq commented Jan 10, 2020

using of LocalServerReceiver.Builder class instead of "plain" new LocalServerReceiver object could be like workaround

Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver.Builder().setPort(8082).build()).authorize("user");

I use Builder class.
I got the same error.

@SquaredCanine
Copy link

I have the same error.

@ncaq
Copy link

ncaq commented Jan 15, 2020

Workaround(for some people)

I want to jetty of eclipse version.
So, I write to sbt below.

"com.google.oauth-client"   % "google-oauth-client-jetty"  % "1.30.3" exclude ("org.mortbay.jetty", "servlet-api"),

google-oauth-client-jettyとjetty-serverのバージョンコンフリクトを解決する - ncaq

@ericraskin
Copy link
Contributor

One more vote for this issue to be resolved. I have an application that loads 9.4 Jetty server version, which is incompatible with 8.2. Can this library be updated to work with 9.4?

@YuanWenqing
Copy link

Same problem!
When will the hotfix version be released?
I'm looking forward to it.

@ericraskin
Copy link
Contributor

I downloaded the code, fixed it and installed it in a local Maven repository. I don't know how to distribute it or get the maintainers to take my change, though. If anybody knows what to do, I'm happy to send the change.

@YuanWenqing
Copy link

This was referenced Feb 16, 2020
@ericraskin
Copy link
Contributor

@YuanWenqing I have attempted to contribute the change, but being new I probably did not do it correctly. The original comment was "I'm not sure this is an upgrade we want." with no further explanation. I have tried again. We'll see if they accept it.

ericraskin added a commit to ericraskin/google-oauth-java-client that referenced this issue Feb 18, 2020
Remove Jetty v8.2 and replace with com.sun.net.httpserver.HttpServer.  Jetty has had breaking changes since 8.2 (specifically with version 9.4).  This causes with conflicts with newer code using later versions of Jetty.  Removing dependency on Jetty resolves this issue.

Fixes googleapis#397.
@chingor13 chingor13 changed the title Jetty exception NoSuchMethodError: org.eclipse.jetty.server.Connector.setHost google-oauth-client-jetty incompatible with Jetty 9.4+ Feb 18, 2020
@chingor13
Copy link
Contributor

We are considering the possibility of providing a separate jetty9 compatible artifact, however, this is a may introduce a dependency management issue for us across our library ecosystem.

Also note that the jetty extensions are not an integral part of the oauth library and are relatively simple adapters/examples of implementing callback handlers for the oauth flow.

elharo pushed a commit that referenced this issue Feb 20, 2020
* feat: Replace Jetty with HttpServer.

Remove Jetty v8.2 and replace with com.sun.net.httpserver.HttpServer.  Jetty has had breaking changes since 8.2 (specifically with version 9.4).  This causes with conflicts with newer code using later versions of Jetty.  Removing dependency on Jetty resolves this issue.

Fixes #397.

* feat: Rewrite findOpenSocket using try with resources

* fix:  Remove commented out Jetty 9.4 code since we are using HttpServer now.

* fix:  Enforce Google coding style.
@anton-erofeev
Copy link

anton-erofeev commented 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>

@shirishjambhorkar
Copy link

shirishjambhorkar commented 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>

@Shahzaibahmad97
Copy link

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>

This worked for me with JDK 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet