few-scooter-86891
08/31/2023, 1:07 AMchilly-king-10285
08/31/2023, 1:07 AMchilly-king-10285
08/31/2023, 1:07 AMhook
set to web_hook
, the URL of your server, the HTTP method (usually POST
), and the body of the request. The body should be a Base64 encoded Jsonnet template that transforms the identity data from Ory to a format your server understands. Here is an example of such a JSON object: json { "hook": "web_hook", "config": { "url": "<https://your-server.com/your-endpoint>", "method": "POST", "body": "base64://{BASE64_ENCODED_JSONNET}" } }
2. Save this JSON object to a file, for example webhook-action.json
. 3. Use the Ory CLI to add this action to your Ory Network project. You can trigger this action after all successful registrations with the following command: bash ory patch identity-config {project-id} \ --add "/selfservice/flows/registration/after/hooks/0=$(cat webhook-action.json)" \ --format yaml
Remember to replace {project-id}
with your actual project ID and {BASE64_ENCODED_JSONNET}
with your actual Base64 encoded Jsonnet. For more information, refer to the [Ory documentation](https://www.ory.sh/docs/actions/integrations/hubspot) and the [Ory Actions webhook guide](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks).few-scooter-86891
08/31/2023, 1:09 AMchilly-king-10285
08/31/2023, 1:09 AMchilly-king-10285
08/31/2023, 1:10 AMweb_hook
action is particularly useful for this purpose as it allows you to trigger any custom, external logic. Here's an example of how you can add a custom hook: 1. Get the Ory Identities config with Ory CLI: bash ## List all available projects ory list projects ## Get config ory get identity-config {project-id} --format yaml > identity-config.yaml
2. Add the hook configuration to the downloaded file: yaml selfservice: flows: recovery: enabled: true ui_url: <http://your.ui/recovery> after: hooks: - hook: your_custom_hook
3. Update the Ory Identities configuration using the file you worked with: bash ory update identity-config {project-id} --file identity-config.yaml
Remember to replace {project-id}
with your actual project ID and your_custom_hook
with your actual hook. For more information, refer to the [Ory documentation on configuring hooks](https://www.ory.sh/docs/kratos/hooks/configure-hooks).few-scooter-86891
08/31/2023, 1:13 AMversion: v0.13.0
serve:
public:
base_url: <http://127.0.0.1:4433/>
cors:
enabled: true
admin:
base_url: <http://kratos:4434/>
selfservice:
default_browser_return_url: <http://localhost:5173/>
allowed_return_urls:
- <http://localhost:5173>
methods:
password:
enabled: true
flows:
error:
ui_url: <http://localhost:5173/error>
settings:
ui_url: <http://localhost:5173/settings>
privileged_session_max_age: 15m
required_aal: highest_available
recovery:
enabled: true
ui_url: <http://localhost:5173/recovery>
use: code
verification:
enabled: true
ui_url: <http://localhost:5173/verification>
use: code
after:
default_browser_return_url: <http://localhost:5173/>
logout:
after:
default_browser_return_url: <http://localhost:5173/login>
login:
ui_url: <http://localhost:5173/login>
lifespan: 10m
registration:
lifespan: 10m
ui_url: <http://localhost:5173/registration>
after:
password:
hooks:
- hook: session
log:
level: debug
format: text
leak_sensitive_values: true
secrets:
cookie:
- ASDVEW-CSASWW-MA-X-CD-BNFD-DSFGREWS
cipher:
- 32-ZXCV-QWERTY-ASD-ZXCASD-12-ASD
ciphers:
algorithm: xchacha20-poly1305
hashers:
algorithm: bcrypt
bcrypt:
cost: 8
identity:
default_schema_id: default
schemas:
- id: default
url: file:///etc/config/kratos/identity.schema.json
courier:
smtp:
connection_uri: <smtps://test:test@smtp.cozymail.dev:465/>
In my configuration, I want to give a webhook to http://localhost:5555 when a user is registered, how do I do that?chilly-king-10285
08/31/2023, 1:13 AMchilly-king-10285
08/31/2023, 1:14 AMweb_hook
action. Here's how you can do it: 1. First, create a Jsonnet file that transforms the identity data from Ory to a format your server understands. Save it as identity_transform.jsonnet
. jsonnet function(ctx) { userId: ctx.identity.id, traits: { email: ctx.identity.traits.email, name: ctx.identity.traits.name, // Add more fields as needed }, }
2. Encode this Jsonnet snippet to Base64: bash cat identity_transform.jsonnet | base64
3. Define the Ory Action as a JSON object. This object should include the hook
set to web_hook
, the URL of your server, the HTTP method (usually POST
), and the body of the request. The body should be the Base64 encoded Jsonnet you created earlier. Save this JSON object to a file, for example webhook-action.json
. json { "hook": "web_hook", "config": { "url": "<http://localhost:5555>", "method": "POST", "body": "base64://{BASE64_ENCODED_JSONNET}" } }
4. Add this action to your Ory Network project using the Ory CLI. You can trigger this action after all successful registrations with the following command: bash ory patch identity-config {project-id} \ --add "/selfservice/flows/registration/after/hooks/0=$(cat webhook-action.json)" \ --format yaml
Remember to replace {project-id}
with your actual project ID and {BASE64_ENCODED_JSONNET}
with your actual Base64 encoded Jsonnet. Finally, add the hook to your configuration file under the registration
flow: yaml selfservice: flows: registration: after: password: hooks: - hook: session - hook: web_hook config: url: <http://localhost:5555> method: POST body: base64://{BASE64_ENCODED_JSONNET}
For more information, refer to the [Ory documentation](https://www.ory.sh/docs/actions/integrations/hubspot) and the [Ory Actions webhook guide](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks).few-scooter-86891
08/31/2023, 1:16 AMchilly-king-10285
08/31/2023, 1:16 AMchilly-king-10285
08/31/2023, 1:16 AMfew-scooter-86891
08/31/2023, 1:18 AMchilly-king-10285
08/31/2023, 1:18 AMchilly-king-10285
08/31/2023, 1:18 AMafter
registration flow. To use it, you must define secrets for secret rotation. [More details](https://www.ory.sh/docs/actions/session) 2. `revoke_active_sessions`: This hook revokes all other active sessions of the user on successful login. It can only be used with the login flow. [More details](https://www.ory.sh/docs/actions/revoke-active-sessions) 3. `require_verified_address`: This hook allows users to sign in only when they have verified their email address. It can only be used with the after
login flow, password
method only. [More details](https://www.ory.sh/docs/actions/require-verified-address) 4. `web_hook`: This hook allows triggering external and custom logic. It can be used with all flows and methods except error and logout. This is the only action type available for the after
settings flow. [More details](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks) For more information, refer to the [Ory documentation on configuring hooks](https://www.ory.sh/docs/kratos/hooks/configure-hooks).few-scooter-86891
08/31/2023, 6:38 AMchilly-king-10285
08/31/2023, 6:38 AMchilly-king-10285
08/31/2023, 6:39 AMdelightful-garage-16669
09/21/2023, 9:22 AMchilly-king-10285
09/21/2023, 9:22 AMchilly-king-10285
09/21/2023, 9:22 AMchilly-king-10285
09/21/2023, 9:23 AMchilly-king-10285
09/21/2023, 9:23 AM