Skip to content

[Java][jersey2] Enable OAuth2 debug stream #6461

@sebastien-rosset

Description

@sebastien-rosset

In the Jersey2 Java client, it would be useful to conditionally enable the OAuth2 debug stream when debug is enabled for the client.

For example, with client credentials, the following exception is raised:

java.lang.IllegalArgumentException: Response body is incorrect. Can't extract a token from an empty string
	at com.github.scribejava.core.utils.Preconditions.check(Preconditions.java:49)
	at com.github.scribejava.core.utils.Preconditions.checkEmptyString(Preconditions.java:31)
	at com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extract(OAuth2AccessTokenJsonExtractor.java:37)
	at com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extract(OAuth2AccessTokenJsonExtractor.java:18)
	at com.github.scribejava.core.oauth.OAuth20Service.sendAccessTokenRequestSync(OAuth20Service.java:53)
	at com.github.scribejava.core.oauth.OAuth20Service.getAccessTokenClientCredentialsGrant(OAuth20Service.java:295)
	at ....client.auth.OAuth.obtainAccessToken(OAuth.java:161)
	at .....auth.OAuth.applyToParams(OAuth.java:112)
	at ....ApiClient.updateParamsForAuth(ApiClient.java:1231)
	at ....ApiClient.invokeAPI(ApiClient.java:1048)
	...

My suggestion is that at this line:

    service = new ServiceBuilder(clientId)
        .apiSecret(clientSecret)
        .build(authApi);

We conditionally add a call to debug():

    service = new ServiceBuilder(clientId)
        .apiSecret(clientSecret).debug()
        .build(authApi);

This would make it possible to troubleshoot OAuth2 without running a debugger or changing the library. Since the data may be sensitive, we should have a specific debug flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions