billowy-toddler-17598
10/23/2023, 2:46 PMexternal_id for an Ory Identity during registration. The options I have explored so far are:
• Use a PostRegistrationPrePersistHook to update the metadata of the identity with the external_id. However, the admin/identities APIs do not allow for lookup or filtering by metadata fields.
• Use a PostRegistrationPostPersistHook to externally store a mapping from the generated Ory identity.id to the external_id. However, since the webhook is non-blocking, if it fails to reach the downstream service or returns an error, there’s no way to abort the registration.
Are there any other options?careful-rain-13694
10/23/2023, 2:55 PMcareful-rain-13694
10/23/2023, 2:55 PMcareful-rain-13694
10/23/2023, 2:58 PMresponse.parse to true 😉careful-rain-13694
10/23/2023, 2:59 PM{
"id": "aa3adcc5-717e-4427-81c8-181bc4326492",
"error": {
"code": 500,
"status": "Internal Server Error",
"message": "error while parsing webhook response: got no validation errors"
},
"created_at": "2023-10-23T14:57:38.103252Z",
"updated_at": "2023-10-23T14:57:38.103252Z"
}billowy-toddler-17598
10/23/2023, 3:07 PMPostRegistrationPrePersistHook which does not provide the identity.id in the hook since it has not been generated or persisted at that point in the flow.careful-rain-13694
10/23/2023, 3:11 PMafter and the identity id is available from there (and the identity is not created in the end - if a failure happens downstream). Would that fit your initial need somehow?billowy-toddler-17598
10/23/2023, 3:25 PM00000000-0000-0000-0000-000000000000 for the identity id. My config for reference:
registration:
lifespan: 10m
ui_url: <http://127.0.0.1:4455/registration>
after:
password:
hooks:
- hook: web_hook
config:
url: <http://host.docker.internal:4000/user>
method: POST
body: file:///etc/config/kratos/registration.jsonnet
response:
parse: true
- hook: sessioncareful-rain-13694
10/23/2023, 3:30 PMregistration.jsonnet file please?careful-rain-13694
10/23/2023, 3:31 PMregistration:
lifespan: 10m
ui_url: <http://127.0.0.1:4455/registration>
after:
oidc:
hooks:
- hook: session
- hook: show_verification_ui
- hook: web_hook
config:
url: <http://host.docker.internal:1337/master/identities>
method: POST
body: file:///etc/config/kratos/hooks/register.jsonnet
response:
ignore: false
parse: truebillowy-toddler-17598
10/23/2023, 3:31 PMfunction(ctx) {
flow_id: ctx.flow.id,
identity: ctx.identity,
}careful-rain-13694
10/23/2023, 3:32 PMfunction(ctx) {
identityId: ctx.identity.id,
email: ctx.identity.traits.email,
name: ctx.identity.traits.name
}
Yours does not look wrong at first sightbillowy-toddler-17598
10/23/2023, 3:33 PMbillowy-toddler-17598
10/23/2023, 3:37 PMmagnificent-energy-493
billowy-toddler-17598
10/23/2023, 4:40 PMcareful-rain-13694
10/23/2023, 5:14 PMcareful-rain-13694
10/23/2023, 5:14 PMregistration flow config (as an example):
registration:
lifespan: 10m
ui_url: <http://127.0.0.1:4455/registration>
after:
oidc:
hooks:
- hook: session
- hook: show_verification_ui
- hook: web_hook
config:
url: <http://host.docker.internal:8080/master/identities>
method: POST
body: file:///etc/config/kratos/hooks/register.jsonnet
response:
ignore: false
parse: true
password:
hooks:
- hook: session
- hook: web_hook
config:
url: <http://host.docker.internal:8080/master/identities>
method: POST
body: file:///etc/config/kratos/hooks/register.jsonnet
response:
ignore: false
parse: truebillowy-toddler-17598
10/23/2023, 5:32 PMidentity.id - reading the code, this seems to be the intended behaviour (as not persisted yet, and ID is generated on DB persistence)?billowy-toddler-17598
10/23/2023, 5:34 PMidentity.id on password after hook when parse set to true?careful-rain-13694
10/23/2023, 5:56 PMidentity.id value from the other side so it did not fail but it is valued as "00000000-0000-0000-0000-000000000000 indeed. My bad, sorry 🙏billowy-toddler-17598
10/24/2023, 4:51 AMcareful-rain-13694
10/24/2023, 6:59 AMmagnificent-energy-493
not persisted yet, and ID is generated on DB persistenceI am not sure if this is the behaviour but will investigage and follow up here
magnificent-energy-493
billowy-toddler-17598
10/24/2023, 8:42 AMDoes the external ID exist for the identifier/email before you create the identity in Ory?No, we’re planning to generate it as part of the registration process. It serves as a user identifier, such as
user_01ARZ3NDEKTSV4RRFFQ69G5FAV. We prefer not to use Ory’s generated UUID elsewhere in the system, and from this issue, it doesn’t seem possible to specify a custom identifier.id.
Why is the “update identity metadata” during registration hook not an option?The
identifier.id is not available at this point, so we cannot create the external_id to identity.id mapping
Why does the webhook need to be blocking on registration? Some condition on the external ID that not all registrations are accepted?If the webhook fails, registration should fail. If the webhook is asynchronous, there’s no guarantee it will be processed, potentially leaving the
external_id to identity.id mapping incomplete. This would mean the entity would exist in Ory but not in our other system.refined-architect-59368
12/13/2023, 2:43 PM00000000-0000-0000-0000-000000000000) in `identity.id`; resolution: ensure the session hook is defined after the other webhooks. Apparently when this executes, subsequently defined hooks are (silently) ignored.