ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
142 stars 85 forks source link

[Dart ory_kratos_client] Unable to build `Update...FlowBody` #290

Open Nelfimov opened 1 year ago

Nelfimov commented 1 year ago

Preflight checklist

Ory Network Project

No response

Describe the bug

updateRegistrationFlowBody requires

Unfortunately creating UpdateRegistrationFlowBody provides only oneOf, whereas auto-generated docs describe the required for me arguments like method, traits and so on.

I have tried creating flow body with following snippets with no success:

1 ```dart final body = UpdateRegistrationFlowBody((b) => b ..oneOf = UpdateRegistrationFlowWithPasswordMethod((p) => p ..password = password ..traits = Traits((t) => t..email = email))); kratosClient .updateRegistrationFlow( flow: registrationFlow.id, updateRegistrationFlowBody: body, ) ```
2 ```dart final body = UpdateRegistrationFlowBody((b) => b ..oneOf = OneOf.of( UpdateRegistrationFlowWithPasswordMethod( (b) => b..password = password ) ) ); ```

This package however provides needed function to create flow body - SubmitSelfServiceRegistrationFlowBody

Reproducing the bug

  1. Create RegistrationFlow
  2. Try to update its body

Relevant log output

No response

Relevant configuration

No response

Version

0.13.1

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

None

Additional Context

No response

MickaelBenasse commented 1 year ago

@Nelfimov Hi, I finally found a solution after really a long time of digging. I had the same problem as you. So, first of all, we missing a lot of documentation on the dart client. You will need two package in order to have it working: OneOf and built_value.

Then I had it working doing so (this is maybe not the best way of doing it but since it was a error and try attempt, I didn't wanted to loose more time having it working):

final Response<SuccessfulNativeRegistration> response;
final JsonObject jsonObject = JsonObject(registrationModel.toJson());

    final UpdateRegistrationFlowBody registrationFlowBody =
        UpdateRegistrationFlowBody(
      (UpdateRegistrationFlowBodyBuilder flow) => flow
        ..oneOf = OneOf.fromValue1(
          value: UpdateRegistrationFlowWithPasswordMethod(
            (UpdateRegistrationFlowWithPasswordMethodBuilder builder) => builder
              ..csrfToken = ''
              ..traits = jsonObject
              ..method = 'password'
              ..password = registrationModel.password,
          ),
        ),
    );

      response = await _oryFrontEnd.updateRegistrationFlow(
        flow: url,
        updateRegistrationFlowBody: registrationFlowBody,
      );

Hope it will help you in future development !