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

Invalid structure generated response from Kratos, error is swallowed #326

Open
5 tasks done
bweston92 opened this issue Feb 13, 2024 · 1 comment
Open
5 tasks done
Labels
bug Something is not working.

Comments

@bweston92
Copy link

Preflight checklist

Ory Network Project

No response

Describe the bug

There is a bug in the Kratos Golang client, where the oneOf(UiNodeAttributes) is always multiple because they all have node_type This error is being returned https://github.com/ory/kratos-client-go/blob/e9aeb0ece9b90a58659db5287a7d4b895d493209/model_ui_node_attributes.go#L141

This error is discarded too because it swallowed here https://github.com/ory/kratos-client-go/blob/e9aeb0ece9b90a58659db5287a7d4b895d493209/model_ui_node.go#L202-L204

Reproducing the bug

package main

import (
	"encoding/json"
	kratos "github.com/ory/kratos-client-go"
	"log"
)

var data = []byte(`{
  "id": "f616cef9-d05b-45ee-aa15-df3e43aadcc6",
  "type": "browser",
  "expires_at": "2024-02-13T15:25:28.317672Z",
  "issued_at": "2024-02-13T15:15:28.317672Z",
  "request_url": "[REDACTED]",
  "return_to": "[REDACTED]",
  "ui": {
    "action": "[REDACTED]/.ory/kratos/public/self-service/login?flow=f616cef9-d05b-45ee-aa15-df3e43aadcc6",
    "method": "POST",
    "nodes": [
      {
        "type": "input",
        "group": "default",
        "attributes": {
          "name": "csrf_token",
          "type": "hidden",
          "value": "0rDQ4YfJvOHPgeedwcI6ySPHM9vXWntmu9aYS9iIDLfvk0xVdyMwidYFWk7TP/9U7nkZ2pW3gi4IaS7x/XV7/g==",
          "required": true,
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {}
      },
      {
        "type": "input",
        "group": "default",
        "attributes": {
          "name": "identifier",
          "type": "text",
          "value": "",
          "required": true,
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {
          "label": {
            "id": 1070004,
            "text": "ID",
            "type": "info"
          }
        }
      },
      {
        "type": "input",
        "group": "password",
        "attributes": {
          "name": "password",
          "type": "password",
          "required": true,
          "autocomplete": "current-password",
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {
          "label": {
            "id": 1070001,
            "text": "Password",
            "type": "info"
          }
        }
      },
      {
        "type": "input",
        "group": "password",
        "attributes": {
          "name": "method",
          "type": "submit",
          "value": "password",
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {
          "label": {
            "id": 1010001,
            "text": "Sign in",
            "type": "info",
            "context": {}
          }
        }
      }
    ]
  },
  "created_at": "2024-02-13T15:15:28.322643Z",
  "updated_at": "2024-02-13T15:15:28.322643Z",
  "refresh": false,
  "requested_aal": "aal1"
}`)

func main() {
	var parsed *kratos.LoginFlow
	if err := json.Unmarshal(data, &parsed); err != nil {
		log.Fatalf("unable to parse %s", err)
	}

	for _, v := range parsed.Ui.Nodes {
		log.Printf("%+v\n", v.Attributes)
	}
}

Relevant log output

2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}
2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}
2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}
2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}


### Relevant configuration

_No response_

### Version

`require github.com/ory/kratos-client-go v1.0.0`

### On which operating system are you observing this issue?

None

### In which environment are you deploying?

None

### Additional Context

_No response_
@bweston92 bweston92 added the bug Something is not working. label Feb 13, 2024
@bweston92
Copy link
Author

bweston92 commented Feb 13, 2024

Adding the generator option useOneOfDiscriminatorLookup=true does it correctly.

openapi-generator-cli generate -i api/openapi.yaml -g go --additional-properties="useOneOfDiscriminatorLookup=true"

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

1 participant