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.

Oath class cast exception in AuthConfig

See original GitHub issue

Version 3.0.3 affected, version 2.9.0 is not affected.

In line 231 this.service = (OAuth10aService) getOauthService(isOAuth1, addEmptyTokenToBaseString); but getOauthService returns OAuthService with incompatible to OAuth10aService implementation: OAuth20Service. This leads to:

java.lang.ClassCastException: com.github.scribejava.core.oauth.OAuth20Service cannot be cast to com.github.scribejava.core.oauth.OAuth10aService

	at io.restassured.internal.http.AuthConfig$OAuthSigner.process(AuthConfig.java:231)
	at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)

Sample execution:

given()
        .accept("application/zip")
.when()
        .auth().oauth2(token, QUERY_STRING)
        .get(Urls.pathToTest)
.then().log().all()

One note: without QUERY_STRING parameter it is working fine (and does not require com.github.scribejava optional dependency).

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
chucknelsoncommented, Aug 30, 2017

Also experiencing this problem with a slightly different use - simply trying to set default OAuth2 authentication for all requests:

RestAssured.authentication = RestAssured.oauth2(authToken);

I receive the same exception as reported by @kmaterka above.

To work around this I just explicitly create the OAuth2 scheme:

PreemptiveOAuth2HeaderScheme myScheme = new PreemptiveOAuth2HeaderScheme();
myScheme.setAccessToken(authToken);
RestAssured.authentication = myScheme;

Simply calling oauth2(token) should work based on what I see in the docs.

1reaction
johanhalebycommented, Aug 31, 2017

@chucknelson Your problem has been addressed in master. Please try version 3.0.4-SNAPSHOT after having added the following maven repo:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Explanation of ClassCastException in Java - Stack Overflow
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. So,...
Read more >
A ClassCastException may occur if two different JAX-RPC ...
A java.lang.ClassCastException error may occur if two different JAX-RPC Web service clients are running in the same Java.
Read more >
ClassCastException (Java Platform SE 7 ) - Oracle Help Center
Class ClassCastException ​​ Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not...
Read more >
2021年08月_weixin_39703561的博客_CSDN博客
2021-01-12. Not reusing HTTP connections via a pool? 2021-01-12. Oath class cast exception in AuthConfig. 2021-01-12. RARBG still has errors. 2021-01-12 ...
Read more >
How to resolve a ClassCastException error message in ...
Contains information about resolving a ClassCastException error and converting data types. Spectrum supports different data types like integer, string, ...
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