Skip to content

Unable to create identity with recovery address using kratos-client-go #4454

@blackshady

Description

@blackshady

Preflight checklist

Ory Network Project

No response

Describe the bug

When using kratos-client-go to create an identity with a recovery address, the request fails unless an id is manually provided in the RecoveryAddress struct.
Even though the ID is expected to be auto-generated, the client throws the following error if it's omitted:

uuid: incorrect UUID length 0 in string ""

This issue appears similar to a previously reported and fixed bug for VerifiableAddress:
🔗 #2506 (comment)

I have created a PR for this bug here
🔗 #4455

Reproducing the bug

This is an example in Golang

package main

import (
	"context"
	"fmt"
	"github.com/google/uuid"
	client "github.com/ory/kratos-client-go"
)

func CreateIdentityWithRecoveryAddress(ctx context.Context, api *client.APIClient, email, firstName, lastName string) error {
	state := "active"

	body := client.CreateIdentityBody{
		SchemaId: "default",
		State:    &state,
		Traits: map[string]interface{}{
			"name": map[string]interface{}{
				"first": firstName,
				"last":  lastName,
			},
			"email": email,
		},
		RecoveryAddresses: []client.RecoveryIdentityAddress{
			{
				Value: email,
				Via:   "email",
				// Id is intentionally omitted to trigger the bug
			},
		},
	}

	identity, resp, err := api.Admin.IdentityAPI.
		CreateIdentity(ctx).
		CreateIdentityBody(body).
		Execute()

	if resp != nil {
		defer resp.Body.Close()
	}

	if err != nil {
		fmt.Println("Error creating identity:", err)
		return err
	}

	fmt.Println("Created identity ID:", identity.Id)
	return nil
}

Sample using curl

curl -X POST http://localhost:4434/identities \
  -H "Content-Type: application/json" \
  -d '{
    "schema_id": "default",
    "state": "active",
    "traits": {
      "email": "[email protected]",
      "name": {
        "first": "Test",
        "last": "User"
      }
    },
    "recovery_addresses": [
      {
        "value": "[email protected]",
        "via": "email"
        // intentionally missing "id"
      }
    ]
  }'

The error response

{"code":400,"message":"uuid: incorrect UUID length 0 in string \"\"","status":"Bad Request"}}

Relevant log output

{"code":400,"message":"uuid: incorrect UUID length 0 in string \"\"","status":"Bad Request"}}

Relevant configuration

Version

v1.3.1

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Docker Compose

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions