<@U04UQ68083H> hi, we have multiple clients with a...
# ory-copilot
f
@chilly-king-10285 hi, we have multiple clients with a very equal domain e.g. *.example.com . How can I set the allowed redirect_url in an oauth2 client?
b
A message from kapa.ai
To set allowed redirect URLs for multiple clients with similar domains in an OAuth2 client configuration, you can use wildcard patterns. Here's how you can do it: 1. When creating or updating an OAuth2 client, you can specify multiple redirect URIs using the
redirect-uri
option. 2. For domains with similar patterns, you can use a wildcard () to match multiple subdomains. Here's an example of how to set this up using the Ory CLI: ``` ory create oauth2-client \ --grant-type authorization_code \ --response-type code \ --scope openid --scope offline_access \ --redirect-uri https://.example.com/callback
Copy code
This command creates an OAuth2 client that allows redirect URIs matching the pattern `https://*.<http://example.com/callback|example.com/callback>`, which would cover all subdomains of <http://example.com|example.com>.  If you need to update an existing client, you can use the `update` command instead:
ory update oauth2-client {client.id} \ --redirect-uri https://*.example.com/callback ``` [Manage OAuth 2.0 and OpenID Connect clients](https://www.ory.sh/docs/hydra/guides/oauth2-clients#create-oauth2-client) Remember that when using wildcards, you should be cautious and specific to avoid potential security risks. It's generally safer to explicitly list all allowed redirect URIs if possible. Also, note that some OAuth2 providers might not support wildcard patterns for redirect URIs due to security considerations. In such cases, you would need to list each allowed redirect URI separately.
f
@chilly-king-10285 that's not correct. I can not use wildcard pattern. Which opens are possible instead?
b
A message from kapa.ai
If wildcard patterns are not supported for redirect URIs, you will need to specify each allowed redirect URI individually. This means that for each client, you will need to add a separate redirect URI. Here's an example of how to set this up using the Ory CLI:
Copy code
bash ory update oauth2-client {client.id} \   --redirect-uri <https://client1.example.com/callback> \   --redirect-uri <https://client2.example.com/callback> \   --redirect-uri <https://client3.example.com/callback>
In this example,
client.id
is the ID of the OAuth2 client you want to update, and
<https://client1.example.com/callback>
,
<https://client2.example.com/callback>
, and
<https://client3.example.com/callback>
are the redirect URIs for each client. Remember to replace
{client.id}
with the actual ID of your OAuth2 client, and replace the example redirect URIs with your actual redirect URIs. You can find more information about updating OAuth2 clients in the [Ory CLI documentation](https://www.ory.sh/docs/cli/ory-update-oauth2-client#options).
f
@chilly-king-10285 not sure if it's practicable for me to add a redirect-uri for every domain. Can I redirect to a special page with redirect me again to the other domains?
b
A message from kapa.ai
Yes, you can set up a central redirect page that handles further redirection to the appropriate domain. This approach is often used when you have a large number of potential redirect URIs or when you want to perform additional processing before redirecting the user. Here's a general idea of how you can set this up: 1. Set the redirect URI in your OAuth2 client configuration to point to your central redirect page. For example:
Copy code
bash ory update oauth2-client {client.id} \   --redirect-uri <https://central.example.com/redirect>
2. In your central redirect page, you can then determine the appropriate final redirect URI based on the state parameter, user information, or other factors. You can then redirect the user to the final redirect URI. Remember to ensure that your central redirect page is secure and does not allow open redirection, as this could be exploited by attackers. You can find more information about setting redirect URIs in the [Ory CLI documentation](https://www.ory.sh/docs/cli/ory-update-oauth2-client#options). Also, note that the exact implementation of your central redirect page will depend on your specific requirements and the technology stack you are using.