<@U04UQ68083H> is there a way to programmatically ...
# ory-copilot
b
@chilly-king-10285 is there a way to programmatically create api keys? I want to create one for my local environment
c
A message from kapa.ai
Yes, you can create API keys programmatically for your local environment using the Ory Console. Here are the steps to create an API key: 1. Go to the [Ory Console](https://console.ory.sh/). 2. Navigate to Access & APIs. 3. Click the + icon in the API Keys section. 4. Enter the API Key name and click Create API Key. 5. Copy the created API Key from the prompt that shows at the bottom right of the screen. Please note that the API Key you created is displayed only once. When you close the prompt, you can't access the key again. Make sure to save the API Key before you close the prompt or reload the page. API Keys are bound to an Ory Network project, and not to a specific user. This means that any user with access to the API Key can perform the operations that the API Key allows, even if they are no longer part of the project. Make sure to keep your API Keys secure and rotate them if necessary. You can use the API Key in API calls, SDK calls, or command-line interactions. Ory API Keys have a
ory_apikey_
or
ory_pat_
, which makes it easy to identify them when analyzing code. For example, when calling the Admin API at
/admin/identities
, include the API Key in the
Authorization
header:
Copy code
GET /admin/identities HTTP/1.1   Host: {project.slug}.<http://projects.oryapis.com|projects.oryapis.com>   Accept: application/json   Authorization: Bearer {API-Key}
Please note that to perform this operation, you must be authenticated by means of one of the following methods:
oryNetworkCookie
. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/concepts/personal-access-token#authorizing-ory-network-project-admin-apis).
b
@chilly-king-10285 This is created using the console though. I'm looking for a way to create them locally and use them in my local environment.
c
A message from kapa.ai
I'm sorry for the confusion, but based on the provided knowledge sources, there's no direct information about creating API keys programmatically or locally without using the Ory Console. The Ory Console is the recommended way to create API keys as per the [Ory documentation](https://www.ory.sh/docs/concepts/personal-access-token#authorizing-ory-network-project-admin-apis). Once you've created an API key, you can use it in your local environment by exporting it as an environment variable. Here's an example of how to do this:
Copy code
bash export ORY_PAT=YOUR_API_KEY # API Key copied from the Ory Console, 'ory_pat' prefix included.
This command sets the
ORY_PAT
environment variable to your API key, which can then be used by your application. For more detailed information or other methods of creating API keys, you may want to refer to the complete Ory documentation or the Ory API reference.
m
@brash-raincoat-15175 When self-hosting Ory the admin API is directly exposed and how you secure it (for example with something like API keys) is up to you.
b
@magnificent-energy-493 Thanks. However, is there a configuration for that? Can I tell Ory to secure its Admin API with a key that I provide in a yaml?
m
when you are self-hosting Ory the Admin API is just there, there is no built-in mechanism to secure it. You can use something like Ory Oathkeeper to protect this API and how you authenticate is up to you, it can be any auth mechanism that you think is good here.
In this example we use NGINX to secure the admin APIs and load balance: https://www.ory.sh/docs/kratos/guides/deploy-kratos-example