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

Kratos PHP SDK: ISO 8601 encoded dates cannot be parsed as DateTime #1961

Closed
3 of 6 tasks
nohns opened this issue Nov 17, 2021 · 5 comments
Closed
3 of 6 tasks

Kratos PHP SDK: ISO 8601 encoded dates cannot be parsed as DateTime #1961

nohns opened this issue Nov 17, 2021 · 5 comments
Labels
bug Something is not working.
Milestone

Comments

@nohns
Copy link

nohns commented Nov 17, 2021

Preflight checklist

Describe the bug

It would seem that the ISO 8601 encoded dates, sent in the /sessions/whoami JSON response, is in a format that the DateTime constructor in PHP cannot parse.

The SDK itself does not produce errors but the output is incorrect. The dates that are in a bad format and are deserialized as 1970-01-01 00:00:00, because the parsing fails silently.

I debugged the issue, and found that in my case some of the dates are parseable such as the "identity.created_at" field and others like "expires_at" are not. It would seem that PHP do not like the long miliseconds part of the date. Through trial and error, I figured it starts erroring when the millis part of the date is 9 digits or more. Anything below that is fine, and that is why it works with some of the dates.

Here is a slice of the session data:
{ "expires_at":"2021-11-18T20:46:52.404576263Z", "authenticated_at":"2021-11-17T20:46:52.438441763Z", ... "identity":{ ... "created_at":"2021-11-17T20:46:52.390087Z", "updated_at":"2021-11-17T20:46:52.390087Z" } }

Reproducing the bug

  1. Running the ORY Kratos Quickstart
  2. Try using the Kratos Client PHP SDK
  3. Make a request to an endpoint and check the dates of the response models

Relevant log output

DateTime::__construct(): Failed to parse time string (2021-11-18T20:46:52.404576263Z) at position 0 (2): The timezone could not be found in the database

Relevant configuration

No response

Version

v0.8.0-alpha.3

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Docker Compose

Additional Context

No response

@nohns nohns added the bug Something is not working. label Nov 17, 2021
@aeneasr
Copy link
Member

aeneasr commented Nov 18, 2021

Oh damn, that's an interesting bug. Could it be related to your PHP version or does this affect all PHP versions? The format itself is complaint with the RFC afaik.

@NickUfer
Copy link
Contributor

I will look into this later. PHP is built different... when it comes to standardized stuff that works in every other programming language it may not work in PHP. I already tried to fix this once in the generator but it seems there is more work to do: OpenAPITools/openapi-generator#7943

@nohns
Copy link
Author

nohns commented Nov 18, 2021

Im using PHP 7.4.25 for macOS 12.0.1 Monterey arm64 build. But as @NickUfer pointed out, it looks like there already was a fix made, but it does not seem like is enough :)

Here is a link to the code for deserialization of DateTimes in the generated code:
https://github.com/ory/kratos-client-php/blob/556c84db83d64a4447d3921c3a44e0c82966a9d6/lib/ObjectSerializer.php#L320

@NickUfer
Copy link
Contributor

Okay, I tested it and this seems to be a problem in versions <= php7.4. It works without any problems with php8.0, even without the workaround. I think you should upgrade to php8.0 if it's possible... I also think there is no other fix for that except for cutting the string before creating a DateTime out of it, but such a solution would not be accepted in the generator project as it is too hacky.
If you can't upgrade to 8.0 and need that fix I'd suggest making a fork of the php client and implementing your own fix for that... or just write the fix straight into the vendor folder but that's really not the way to do things.

@aeneasr aeneasr added this to the v0.10.0-alpha.1 milestone Mar 7, 2022
@aeneasr aeneasr modified the milestones: v0.10.0-alpha.1, v1.0.0 May 30, 2022
@kmherrmann
Copy link
Contributor

Closing as it is 18 months old and relates to an old PHP version. please reopen if required.

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

No branches or pull requests

4 participants