<@U04UQ68083H> How can I test a hook locally?
# ory-copilot
b
@chilly-king-10285 How can I test a hook locally?
b
A message from kapa.ai
Based on the knowledge sources, there are a few ways to test hooks locally when working with Ory products: ## Using Ory Tunnel for local development Ory Tunnel is a tool specifically designed for local development that helps you test your hooks by exposing Ory APIs under the same top-level domain as your application. This prevents CORS issues during testing. To use Ory Tunnel:
Copy code
ory tunnel --project <project-id> --workspace <workspace-id> <http://localhost:3000>
This command creates a connection between your local environment and Ory Network, allowing you to test your hooks locally. [Ory Proxy and Ory Tunnel](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel) ## Testing password migration hooks If you're specifically testing a password migration hook: 1. Import identities with
use_password_migration_hook
set to
true
2. Configure the password migration webhook to point to your local server 3. Implement the webhook to handle the password migration logic 4. Test the login flow to trigger the hook [Password migration using a web hook](https://www.ory.sh/docs/kratos/manage-identities/import-user-accounts-identities#password-migration-using-a-web-hook) ## Testing with custom UI When testing hooks with a custom UI: 1. Configure Ory Network to use UI views hosted on your local machine 2. Use Ory Tunnel to create a connection between your local environment and Ory Network 3. Run your local application and test the flows that trigger your hooks [Configure Ory to use your UI](https://www.ory.sh/docs/kratos/bring-your-own-ui/configure-ory-to-use-your-ui#development) ## Canceling webhooks during testing For testing purposes, you can also implement logic to cancel webhooks for test accounts:
Copy code
function(ctx) if std.startsWith(ctx.identity.traits.email, "test-") then   error "cancel" else   {     user_id: ctx.identity.id   }
This prevents test accounts from triggering actual external integrations during testing. [Canceling webhooks](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks#canceling-webhooks) Remember that Ory Tunnel and Ory Proxy are meant for local development and should not be used in production environments.
b
@chilly-king-10285 This has no value: To access Ory's APIs, use URL
b
A message from kapa.ai
I notice your question is incomplete. You mentioned "This has no value: To access Ory's APIs, use URL" but didn't specify what URL you're referring to or what specific issue you're encountering. Based on the knowledge sources, there are several ways to access Ory's APIs depending on your development context: 1. For local development, you can use Ory Tunnel or Ory Proxy to expose Ory APIs under the same domain as your application: - Ory Tunnel:
ory tunnel --project <project-id> <http://localhost:3000>
[Ory Tunnel](https://www.ory.sh/docs/cli/ory-tunnel#ory-tunnel) - Ory Proxy:
ory proxy --project <project-id> <http://localhost:3000>
[Ory Proxy](https://www.ory.sh/docs/cli/ory-proxy#ory-proxy) 2. When using Ory Proxy, APIs are available under the
/.ory
prefix, for example:
https://<proxy-host>/.ory/ui/login
[Ory Proxy and Ory Tunnel](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel#ory-proxy) 3. For production environments, you can use custom domains with CNAME records [Ory Proxy and Ory Tunnel](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel#ory-proxy) If you could provide more details about your specific use case or what you're trying to accomplish, I'd be happy to provide more targeted assistance.
m
I generally use https://webhook.site/ to test webhooks, idk if that helps in your case 🙂
b
@magnificent-energy-493 Oh nice. My use case is testing a webhook in my local app, tunneled to Ory Network. Will this work?
How else would one test/develop webhooks? Feels like I'm missing something. Is there no URL exposed for the tunnel?
m
So you have a local frontend running that is connected to Ory Network via tunnel. What kind of webhook do you want to test? I assume its not Ory Actions in this case, but some webhook that goes from your frontend to Ory Network and does something @billions-minister-2901?
b
It's a pre-registration hook
Correct, local frontend connected via tunnel
m
apologies I think I still don't understand
pre-registration hook
as far as I understand this calls from Ory Network to some url - what is running locally in this example?
I assume the Ory Actions/webhook target?
b
The URL that I want to call in the pre-reg hook
I'm trying to test an update to my auth flow, part of which is checking some data before registration from Ory (via the webhook)
m
I see - yea that is why I recommended https://webhook.site/ - you could also do something with ngrok probably, but I have no real experience with that.
how would you test webhooks locally normally (in general, not Ory specific)?
b
Not sure - I haven't done it before
m
gotcha - I think ngrok is the most "sophisticated" option https://ngrok.com/docs/getting-started/ for me personally the webhook.site stuff is "good enough" but I only test simple demo apps nowadays
b
Sweet
Yeah webhook is working well enough!
Thanks for the help!