Skip to content

SubmitSelfServiceRegistrationFlowBody's traits is a string. #117

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

Closed
loposkin opened this issue Sep 23, 2021 · 4 comments
Closed

SubmitSelfServiceRegistrationFlowBody's traits is a string. #117

loposkin opened this issue Sep 23, 2021 · 4 comments
Assignees

Comments

@loposkin
Copy link

loposkin commented Sep 23, 2021

Describe the bug

The method V0alpha1Api.submitSelfServiceRegistrationFlowWithHttpInfo needs SubmitSelfServiceRegistrationFlowBody as parameter. The traits field is a string, though the API reference says it should be object (at least for password method). We tried to json encode our traits object to pass it to the constructor. But it results in false body encoding and 400 response code. Here is the debug log of the ApiClient:

2021-09-23 18:58:34,927 [] INFO  okhttp3.OkHttpClient: --> POST http://localhost:4433/self-service/registration?flow=4e964bd3-bc05-42cf-b94e-84d90327e6ce
2021-09-23 18:58:34,927 [] INFO  okhttp3.OkHttpClient: Content-Length: 89
2021-09-23 18:58:34,927 [] INFO  okhttp3.OkHttpClient: Accept: application/json
2021-09-23 18:58:34,927 [] INFO  okhttp3.OkHttpClient: Content-Type: application/json
2021-09-23 18:58:34,927 [] INFO  okhttp3.OkHttpClient: User-Agent: OpenAPI-Generator/v0.7.6-alpha.7/java
2021-09-23 18:58:34,928 [] INFO  okhttp3.OkHttpClient: 
2021-09-23 18:58:34,928 [] INFO  okhttp3.OkHttpClient: {"method":"password","password":"Itso123$$","traits":"{\"email\":\"[email protected]\"}"}
2021-09-23 18:58:34,928 [] INFO  okhttp3.OkHttpClient: --> END POST (89-byte body)
2021-09-23 18:58:34,940 [] INFO  okhttp3.OkHttpClient: <-- 400 Bad Request http://localhost:4433/self-service/registration?flow=4e964bd3-bc05-42cf-b94e-84d90327e6ce (11ms)
2021-09-23 18:58:34,940 [] INFO  okhttp3.OkHttpClient: Cache-Control: private, no-cache, no-store, must-revalidate
2021-09-23 18:58:34,941 [] INFO  okhttp3.OkHttpClient: Content-Type: application/json; charset=utf-8
2021-09-23 18:58:34,941 [] INFO  okhttp3.OkHttpClient: Vary: Origin
2021-09-23 18:58:34,941 [] INFO  okhttp3.OkHttpClient: Vary: Cookie
2021-09-23 18:58:34,941 [] INFO  okhttp3.OkHttpClient: Date: Thu, 23 Sep 2021 16:58:39 GMT
2021-09-23 18:58:34,941 [] INFO  okhttp3.OkHttpClient: Content-Length: 1566
2021-09-23 18:58:34,942 [] INFO  okhttp3.OkHttpClient: 
2021-09-23 18:58:34,942 [] INFO  okhttp3.OkHttpClient: {"id":"4e964bd3-bc05-42cf-b94e-84d90327e6ce","type":"api","expires_at":"2021-09-23T17:08:39.217164403Z","issued_at":"2021-09-23T16:58:39.217164403Z","request_url":"http://localhost:4433/self-service/registration/api","ui":{"action":"http://127.0.0.1:4433/self-service/registration?flow=4e964bd3-bc05-42cf-b94e-84d90327e6ce","method":"POST","nodes":[{"type":"input","group":"default","attributes":{"name":"csrf_token","type":"hidden","value":"","required":true,"disabled":false},"messages":[],"meta":{}},{"type":"input","group":"password","attributes":{"name":"traits.email","type":"email","disabled":false},"messages":[{"id":4000002,"text":"Property email is missing.","type":"error","context":{"property":"email"}}],"meta":{"label":{"id":1070002,"text":"E-Mail","type":"info"}}},{"type":"input","group":"password","attributes":{"name":"password","type":"password","required":true,"disabled":false},"messages":[],"meta":{"label":{"id":1070001,"text":"Password","type":"info"}}},{"type":"input","group":"password","attributes":{"name":"traits.name.first","type":"text","disabled":false},"messages":[],"meta":{"label":{"id":1070002,"text":"First Name","type":"info"}}},{"type":"input","group":"password","attributes":{"name":"traits.name.last","type":"text","disabled":false},"messages":[],"meta":{"label":{"id":1070002,"text":"Last Name","type":"info"}}},{"type":"input","group":"password","attributes":{"name":"method","type":"submit","value":"password","disabled":false},"messages":[],"meta":{"label":{"id":1040001,"text":"Sign up","type":"info","context":{}}}}]}}

2021-09-23 18:58:34,942 [] INFO  okhttp3.OkHttpClient: <-- END HTTP (1566-byte body)

As you can see it looks like, the server fails to decode email trait: Property email is missing.

To Reproduce

Steps to reproduce the behavior:

  1. Construct SubmitSelfServiceRegistrationFlowBody with "password" method and pass the traits object with email to the constructor.
  2. Submit the registration.

Expected behavior

There is SubmitSelfServiceRegistrationFlowWithPasswordMethodBody class, which seems to have right fields, but it can't be passed to the submit function.

One option is to change the field to object, so the user can pass a string or an object. Another option is to provide separate functions for submitting(for both methods).

Environment

  • Client-Version: Java, v0.7.6-alpha.7
  • Server-Version: v0.7.6-alpha.1

Are we missing something?

@aeneasr
Copy link
Member

aeneasr commented Sep 23, 2021

That's strange! The same method appears to be generated correctly for settings:

https://github.com/ory/kratos-client-java/blob/72865bbe47bfb59aa97e2244d96c7b3aa27c37d9/src/main/java/sh/ory/kratos/model/SubmitSelfServiceSettingsFlowBody.java#L49

Not sure what's going on here

@daniel-shuy
Copy link

OpenAPI Generator is incorrectly generating the Java POJOs for polymorphic serialization. It is setting method as the class name instead of discriminator.mapping:
https://github.com/ory/kratos-client-java/blob/3f7c170f2aa77cf35977f197f517457b1a2dc614/src/main/java/sh/ory/kratos/model/SubmitSelfServiceRegistrationFlowBody.java#L50-L52

This is a known issue with OpenAPI Generator (OpenAPITools/openapi-generator#417). If possible, switching from GSON to Jackson should resolve this issue, as Jackson has better polymorphism support (SubmitSelfServiceLoginFlowWithPasswordMethodBody will be generated as a subclass of SubmitSelfServiceRegistrationFlowBody. You can then create an instance of SubmitSelfServiceLoginFlowWithPasswordMethodBody and pass it into V0alpha1Api.submitSelfServiceRegistrationFlowWithHttpInfo(String, SubmitSelfServiceRegistrationFlowBody)).

@aeneasr
Copy link
Member

aeneasr commented Oct 28, 2021

Can you check if this was fixed with kratos 0.8?

@aeneasr
Copy link
Member

aeneasr commented Feb 27, 2022

I believe this is fixed

@aeneasr aeneasr closed this as completed Feb 27, 2022
@aeneasr aeneasr self-assigned this Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants