auth0-java: java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(byte[], okhttp3.MediaType)'

Hello,

after upgrading to the version 1.25.0 (from 1.24.0) i get the error in the title when getting TokenHolder.

My code looks the same as in your docs:

AuthAPI authAPI = new AuthAPI("{YOUR_DOMAIN}", "{YOUR_CLIENT_ID}", "{YOUR_CLIENT_SECRET}");
AuthRequest authRequest = authAPI.requestToken("https://{YOUR_DOMAIN}/api/v2/");
TokenHolder holder = authRequest.execute();
ManagementAPI mgmt = new ManagementAPI("{YOUR_DOMAIN}", holder.getAccessToken());

The problem is this line: TokenHolder holder = authRequest.execute();

In previous versions everything worked great but since update to 1.25.0 it throws the following error:

Caused by: java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(byte[], okhttp3.MediaType)'
        at com.auth0.net.CustomRequest.createRequestBody(CustomRequest.java:50)
        at com.auth0.net.ExtendedBaseRequest.createRequest(ExtendedBaseRequest.java:49)
        at com.auth0.net.BaseRequest.execute(BaseRequest.java:29)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 14
  • Comments: 31 (14 by maintainers)

Commits related to this issue

Most upvoted comments

It could be fixed by adding strictly version into the dependencies

    implementation("com.squareup.okhttp3:okhttp") {
        version {
            strictly '4.9.0'
        }
    }

Or adding the BOM into the dependencyManagement

dependencyManagement {
    imports {
        mavenBom "com.squareup.okhttp3:okhttp-bom:4.9.0"
    }
}

Having the same issue… please fix asap!

It seems to fix the problem! I will test it more thoroughly in the next days but for now this basic call has passed.

Now my pom.xml looks like this:

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>${quarkus.platform.artifact-id}</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp-bom</artifactId>
        <version>4.9.1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
      </dependency>
      <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>logging-interceptor</artifactId>
      </dependency>
      <dependency>
        <groupId>com.squareup.okio</groupId>
        <artifactId>okio</artifactId>
        <version>2.10.0</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

Not pretty but at least it works.

Identical issue, have reverted to 1.24.0 until further updates.

Resolved dependency tree of 1.24.0 looks like:

+--- com.auth0:auth0:1.24.0
|    +--- com.squareup.okhttp3:okhttp:3.14.9
|    |    \--- com.squareup.okio:okio:1.17.2
|    +--- com.squareup.okhttp3:logging-interceptor:3.14.9
|    |    \--- com.squareup.okhttp3:okhttp:3.14.9 (*)
|    +--- com.fasterxml.jackson.core:jackson-databind:2.11.3 (*)
|    +--- commons-codec:commons-codec:1.15 -> 1.14
|    \--- com.auth0:java-jwt:3.11.0
|         +--- com.fasterxml.jackson.core:jackson-databind:2.10.3 -> 2.11.3 (*)
|         \--- commons-codec:commons-codec:1.14

Resolved dependency tree of 1.25.0 looks like:

+--- com.auth0:auth0:1.25.0
|    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 3.14.9
|    |    \--- com.squareup.okio:okio:1.17.2
|    +--- com.squareup.okhttp3:logging-interceptor:3.14.9
|    |    \--- com.squareup.okhttp3:okhttp:3.14.9 (*)
|    +--- com.fasterxml.jackson.core:jackson-databind:2.11.3 (*)
|    +--- commons-codec:commons-codec:1.15 -> 1.14
|    \--- com.auth0:java-jwt:3.11.0
|         +--- com.fasterxml.jackson.core:jackson-databind:2.10.3 -> 2.11.3 (*)
|         \--- commons-codec:commons-codec:1.14

In my case it is okhttp3 version resolution which causes this (I think) as the error seems to relate to the method deprecated in okhttp3 version 4, ie com.squareup.okhttp3:okhttp:4.9.0 -> 3.14.9

But interestingly different versions of okhttp3 are required within com.auth0:auth0:1.25.0 itself:

  • com.squareup.okhttp3:okhttp:4.9.0
  • com.squareup.okhttp3:logging-interceptor:3.14.9 that depends on com.squareup.okhttp3:okhttp:3.14.9

Just an update, I have updated Auth0 to the latest version (currently 1.30.0) and these changes are not necessary in the pom.xml anymore.

I am not using spring, and I don’t see why this is necessary at all.

Was able to reproduce in https://github.com/ivarprudnikov/test-auth0-java-dependency with a build.gradle file:

plugins {
	id 'java'
	id 'application'
	id "org.springframework.boot" version "2.3.6.RELEASE"
	id "io.spring.dependency-management" version "1.0.10.RELEASE"
}

repositories {
    mavenCentral()
	jcenter()
	maven { url = uri("https://jitpack.io") }
}

sourceCompatibility = "11"

dependencies {
	implementation "com.auth0:auth0:1.25.0"
}

mainClassName = 'hello.HelloWorld'

jar {
    baseName = 'test-auth0-gradle'
    version =  '0.1.0'
}

There are Github actions enabled and it tries to run the app which generates the failure we talk about here.

Reopening based on above, thanks for providing the sample to reproduce, we’ll follow up here with additional info once we reproduce and see what the solution may be.

Thanks for the detailed info and dependency tree reports. I’m back from holiday this week; will take a look and hopefully get a fix out soon.