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

Cannot deserialize API response #19

Closed
4 of 6 tasks
gatesn opened this issue May 14, 2023 · 5 comments · Fixed by ory/sdk#332
Closed
4 of 6 tasks

Cannot deserialize API response #19

gatesn opened this issue May 14, 2023 · 5 comments · Fixed by ory/sdk#332
Labels
bug Something is not working.

Comments

@gatesn
Copy link

gatesn commented May 14, 2023

Preflight checklist

Describe the bug

I get an error in the Java client when deserializing a response from the server:

Caused by: java.lang.IllegalArgumentException: Expected the field `grant_types` to be an array in the JSON string but got `null`

Reproducing the bug

Making a call to OAuth2Api#createOAuth2Client

Relevant log output

No response

Relevant configuration

No response

Version

2.1.1

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Binary

Additional Context

The issue is that the OAuth2Api incorrectly checks for null values:

      // ensure the optional json data is an array if present
      if (jsonObj.get("grant_types") != null && !jsonObj.get("grant_types").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `grant_types` to be an array in the JSON string but got `%s`", jsonObj.get("grant_types").toString()));
      }

Instead, it should be:

      // ensure the optional json data is an array if present
      if (!jsonObj.get("grant_types").isJsonNull() && !jsonObj.get("grant_types").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `grant_types` to be an array in the JSON string but got `%s`", jsonObj.get("grant_types").toString()));
      }
@gatesn gatesn added the bug Something is not working. label May 14, 2023
@gatesn
Copy link
Author

gatesn commented May 14, 2023

Looks like it's fixed upstream here: OpenAPITools/openapi-generator#13548

@vmuth85
Copy link

vmuth85 commented Sep 20, 2023

I've got the same issue with the hydra-client-v2.2.0-rc.3. I cannot perform the Authorization Code Flow without setting the 'audience' request parameter. The response of

GET https://www.ory.sh/admin/oauth2/auth/requests/login?challenge=uJQp89szo......GcAez4qV0-V_

looks as follows:

"challenge": "uJQp89szo......GcAez4qV0-V_",
"requested_scope": [
"offline_access",
"openid"
],
"requested_access_token_audience": null,
"skip": true,
"subject": "user",
"oidc_context": {},
...

As you can see, the 'requested_access_token_audience' attribute is null, but the OAuth2LoginRequest.validateJsonObject method doesn't check properly for null values and throws an java.lang.IllegalArgumentException ( "Expected the field requested_access_token_audience to be an array in the JSON string but got null")

The current code

// ensure the required json array is present
      else if (!jsonObj.get("requested_access_token_audience").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `requested_access_token_audience` to be an array in the JSON string but got `%s`", jsonObj.get("requested_access_token_audience").toString()));
      }

has to be changed as follows:

  // ensure the required json array is present
  else if (!jsonObj.get("requested_access_token_audience").isJsonNull() && !jsonObj.get("requested_access_token_audience").isJsonArray()) {
    throw new IllegalArgumentException(String.format("Expected the field `requested_access_token_audience` to be an array in the JSON string but got `%s`", jsonObj.get("requested_access_token_audience").toString()));
  }

@alnr
Copy link

alnr commented Feb 7, 2024

This same issue was reported for the Rust client in the Community Slack.

@aeneasr
Copy link
Member

aeneasr commented Feb 13, 2024

This is fixed now

@aeneasr aeneasr closed this as completed Feb 13, 2024
@MalteBellmann
Copy link

MalteBellmann commented Feb 18, 2024

For me this is not fixed with server and client versions at 2.2.0. I still get the IllegalArgumentException when i call createOAuth2Client. In my case the problematic fields are contacts, redirectUris and responseTypes.

The underlying bug in openapi-generator was fixed in version 7.0.0 (OpenAPITools/openapi-generator#16213 / OpenAPITools/openapi-generator#16212). Currently ory/sdk is at 6.2.1 for Java. The latest version is 7.3.0, here is a PR that updates the java generator to this version: ory/sdk#332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants