Skip to content

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

@lagivan

Description

@lagivan

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.

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions