billions-minister-2901
04/01/2025, 8:51 PMbrief-egg-61061
04/01/2025, 8:51 PMbrief-egg-61061
04/01/2025, 8:51 PMctx object in pre-registration hooks for Ory. In Ory webhooks, which can be used as pre-registration hooks, the ctx object contains information about the registration flow and request details. The ctx object binds the following data: - `flow`: Contains details about the registration flow including ID, expiration time, UI nodes, etc. - `request_headers`: Contains HTTP headers from the request - `request_method`: The HTTP method used (e.g., POST) - `request_url`: The URL of the request For the pre-registration hook specifically (which uses the "before" execution path), the ctx object doesn't include the identity object since the identity hasn't been created yet. The identity object is only available in the "after" execution path. Here's an example of what the ctx object might look like in a pre-registration hook: json { "ctx": { "flow": { "expires_at": "2023-01-31T12:19:35.782238Z", "id": "cec1c06e-48eb-4f9d-abf1-2e287371f4eb", "issued_at": "2023-01-31T11:19:35.782238Z", "oauth2_login_challenge": null, "request_url": "<https://playground.projects.oryapis.com/self-service/registration/browser?return_to=>", "transient_payload": { "custom_data": "test" }, "type": "browser", "ui": { "action": "<http://localhost:4455/self-service/registration?flow=cec1c06e-48eb-4f9d-abf1-2e287371f4eb>", "method": "POST", "nodes": [ // UI nodes for the registration form ] } }, "request_headers": { "Accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ], // Other headers }, "request_method": "POST", "request_url": "<https://playground.projects.oryapis.com/self-service/registration?flow=cec1c06e-48eb-4f9d-abf1-2e287371f4eb>" } } You can access these fields in your Jsonnet template for customizing webhook requests, for example: jsonnet function(ctx) { customData: ctx.flow.transient_payload.custom_data // Other fields you want to include } [Trigger custom logic and integrate with external systems with webhooks](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks#jsonnet-templating) provides more details about the available fields and how to use them in webhook templates.billions-minister-2901
04/01/2025, 8:52 PMbrief-egg-61061
04/01/2025, 8:52 PMbrief-egg-61061
04/01/2025, 8:53 PMhook: web_hook config: response: parse: true 2. Return a 200 OK response from your webhook with a JSON object that includes the identity key containing the metadata you want to set: json { "identity": { "metadata_public": { "the_webhook": "changed this value", "and_added_this_one": "too" }, "metadata_admin": { "the_webhook": "updated this value", "and_this_one": "too" } } } It's important to note that this method replaces the entire metadata object. You cannot update only a single value in metadata_public or metadata_admin - you need to include all values you want to preserve. This functionality is specifically mentioned in the documentation as being available during registration flows: > Modifying the identity is currently only possible during the registration and settings flows. [Trigger custom logic and integrate with external systems with webhooks](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks#modify-identities) provides detailed information about modifying identities through webhooks, including updating metadata. Additionally, if you need to pass complex data types in the metadata, you can use the schema-less nature of the metadata fields, as they support JSON objects with additional properties.