plain-megabyte-75926
12/16/2024, 11:38 AMbrief-egg-61061
12/16/2024, 11:38 AMbrief-egg-61061
12/16/2024, 11:38 AMplain-megabyte-75926
12/17/2024, 8:53 PMbrief-egg-61061
12/17/2024, 8:53 PMbrief-egg-61061
12/17/2024, 8:53 PMplain-megabyte-75926
12/17/2024, 8:56 PMbrief-egg-61061
12/17/2024, 8:56 PMbrief-egg-61061
12/17/2024, 8:56 PMplain-megabyte-75926
12/17/2024, 8:59 PMbrief-egg-61061
12/17/2024, 8:59 PMbrief-egg-61061
12/17/2024, 8:59 PMory_apikey_
or ory_pat_
prefix, which makes it easy to identify them when analyzing code." 5. Flexibility: API Keys can be easily created, rotated, and revoked through the Ory Console, providing better control over access management. 6. Scoping: While not explicitly mentioned in the provided sources, API Keys and Personal Access Tokens can often be scoped to specific permissions or resources, allowing for fine-grained access control. Here's an example of how to use an API Key with Ory, as shown in the documentation: GET /admin/identities HTTP/1.1 Host: $<http://PROJECT_SLUG.projects.oryapis.com|PROJECT_SLUG.projects.oryapis.com> Accept: application/json Authorization: Bearer $API_KEY
This approach is more straightforward and appropriate for most API access scenarios compared to implementing the OAuth Client Credentials Flow. Remember, the choice between API Keys, Personal Access Tokens, and OAuth flows depends on your specific use case and security requirements. For most API users, especially when dealing with Ory's Admin APIs, API Keys or Personal Access Tokens would be the recommended approach.plain-megabyte-75926
12/17/2024, 9:01 PMbrief-egg-61061
12/17/2024, 9:01 PMbrief-egg-61061
12/17/2024, 9:01 PMGET /admin/identities HTTP/1.1 Host: $<http://PROJECT_SLUG.projects.oryapis.com|PROJECT_SLUG.projects.oryapis.com> Accept: application/json Authorization: Bearer $API_KEY
5. Identification: Ory API Keys have specific prefixes for easy identification. As mentioned in the documentation, "Ory API Keys have a ory_apikey_
or ory_pat_
prefix, which makes it easy to identify them when analyzing code." If you're having trouble creating or using API keys within your Ory project, I recommend checking the [Ory Console](https://console.ory.sh/) or reaching out to Ory support for assistance. They should be able to help you set up and use API keys within your system.plain-megabyte-75926
12/17/2024, 9:03 PMbrief-egg-61061
12/17/2024, 9:03 PMbrief-egg-61061
12/17/2024, 9:03 PMplain-megabyte-75926
03/14/2025, 3:06 PMbrief-egg-61061
03/14/2025, 3:06 PMbrief-egg-61061
03/14/2025, 3:07 PMjavascript await ory.acceptOAuth2ConsentRequest({ consentChallenge: consentChallenge, acceptOAuth2ConsentRequest: { session: { access_token: { user_roles: ["admin", "editor"], // Example of adding roles }, }, }, })
### Considerations for Including Roles in JWTs 1. Token Size: Including roles in JWTs increases token size, which means more data transmitted with every API request. 2. Immutability: As mentioned in the [JWT access tokens documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#limitations), "Access Tokens as JSON Web Tokens can't be revoked: You can revoke a JWT token, but the token is still considered valid until the token's expiry time is reached." This means if a user's role changes, they'll still have access with their old role until their token expires. 3. Security Exposure: The [JWT access tokens documentation](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#limitations) also notes that "OAuth 2.0 Access Tokens represent internal state but are public knowledge: An Access Token often contains internal data (such as session data) or other sensitive data (such as user roles and permissions)." This means sensitive role information could potentially be exposed. 4. Complexity vs. Simplicity: For simple role-based access control, including roles in JWTs might be sufficient. However, for more complex permission scenarios, Ory Keto would be more appropriate as mentioned in the [Ory Keto documentation](https://www.ory.sh/docs/ecosystem/projects#ory-keto). ### Best Practices If you decide to include roles in JWTs: 1. Keep tokens short-lived to minimize the window of outdated role information. 2. Consider using the token introspection endpoint to validate tokens, which allows you to check if a token has been revoked. 3. For top-level claims, you'll need to modify the configuration as shown in the documentation: ory patch oauth2-config --project <project-id> --workspace <workspace-id> \ --replace "/oauth2/allowed_top_level_claims=[\"user_roles\"]"
### Conclusion Including roles as claims in JWTs can be appropriate for simpler systems with relatively static role assignments. However, as your permission requirements grow more complex, you might want to consider using Ory Keto for more sophisticated access control, as it's specifically designed for handling complex permission scenarios. The best approach depends on your specific use case, the complexity of your permission model, and how frequently roles change in your system.plain-megabyte-75926
03/21/2025, 10:27 AMbrief-egg-61061
03/21/2025, 10:27 AMbrief-egg-61061
03/21/2025, 10:27 AMdefault_grant_allowed_scope
setting: ory patch oauth2-config "{your-project-id}" \ --replace '/oauth2/client_credentials/default_grant_allowed_scope=true'
As mentioned in the [Migrating from MITREid documentation](https://www.ory.sh/docs/hydra/self-hosted/migrating-from-mitreid), this setting makes Ory grant the OAuth2 Client's allowed scopes when a client requests scopes that are no longer permitted. ### 2. Token Introspection for Validation Instead of breaking the token issuance, you could still issue tokens but use token introspection to validate what the token can actually do: 1. Allow the client to get a token with the requested scopes 2. Use the [token introspection endpoint](https://www.ory.sh/docs/oathkeeper/pipeline/authn#oauth2_introspection) to validate what the token is actually allowed to do 3. Your API can then enforce the actual allowed scopes based on the current subscription level This approach is documented in the Oathkeeper pipeline authenticators section. ### 3. Scope Strategies for Graceful Degradation Ory supports different [scope strategies](https://www.ory.sh/docs/oathkeeper/api-access-rules#scoped-credentials) that could help with graceful degradation: - `hierarchic`: Scope foo
matches foo
, foo.bar
, foo.baz
but not bar
- `wildcard`: Scope foo.*
matches foo
, foo.bar
, foo.baz
but not bar
- `exact`: Scope foo
matches foo
but not bar
nor foo.bar
You could structure your scopes hierarchically based on subscription levels, allowing for graceful degradation. ### 4. Client Modification with Notification If you need to modify the client's allowed scopes, you could: 1. Use the [patchOAuth2Client API](https://www.ory.sh/docs/reference/api) to update the client's allowed scopes 2. Implement a notification system to inform your customers about the change 3. Provide a grace period where both old and new scopes work ### Best Practice Recommendation The most robust approach would be a combination of: 1. Structure your scopes hierarchically based on subscription tiers 2. When a downgrade occurs, update the client's allowed scopes but maintain backward compatibility through scope strategy configuration 3. Use token introspection to enforce the current subscription limitations 4. Notify customers about the change and provide documentation on how to update their integration This approach ensures that existing integrations don't break immediately while still enforcing the subscription limitations appropriately. Would you like more specific details on implementing any of these approaches?plain-megabyte-75926
03/21/2025, 2:05 PMbrief-egg-61061
03/21/2025, 2:05 PMbrief-egg-61061
03/21/2025, 2:06 PMory create oauth2-client \ --grant-type client_credentials \ --scope my-scope \ --token-endpoint-auth-method client_secret_basic
2. Custom claims in tokens: As we discussed previously, you could include role information as custom claims in the JWT access token. This would allow your services to understand what role the client application has. 3. Client-specific permissions: You could create different OAuth2 clients with different scopes for different service roles, effectively using the client ID itself to represent a specific service role. Remember that in the Client Credentials flow, there is no user context - the client itself is being authenticated. As mentioned in the [OAuth2 concepts documentation](https://www.ory.sh/docs/oauth2-oidc/overview/oauth2-concepts#getting-a-client-token), this flow is "designed for non-interactive applications, such as automated processes or microservices, where the client is authenticated using its client ID and client secret." For more complex authorization scenarios, you might want to consider using Ory Keto alongside the OAuth Client Credentials flow, where the client gets authenticated via OAuth2, but the actual permission checks are handled by Keto. Would you like more specific information about implementing any of these approaches for your service roles?plain-megabyte-75926
03/21/2025, 2:07 PMbrief-egg-61061
03/21/2025, 2:07 PMbrief-egg-61061
03/21/2025, 2:08 PMory create oauth2-client \ --grant-type client_credentials \ --scope my-scope \ --token-endpoint-auth-method client_secret_basic
3. Standardized Protocol: OAuth2 is a widely adopted standard with robust security practices. 4. Flexible Authentication Methods: Ory supports multiple authentication methods for clients, including: - Basic Authentication (client ID and secret in Authorization header) - Body Authentication (client ID and secret in request body) - JWT Bearer profile (using signed JWTs) as described in the [JWT Bearer documentation](https://www.ory.sh/docs/oauth2-oidc/client-credentials#jwt-bearer-profile-for-oauth2-client-authentication) ### Implementation Example Here's a basic example of how to implement this flow from the [Ory documentation](https://www.ory.sh/blog/run-oauth2-server-open-source-api-security): 1. Create an OAuth2 client: ory create oauth2-client --project $project_id \ --name "Client Credentials Demo" \ --grant-type client_credentials
2. Exchange credentials for a token: ory perform client-credentials --project $project_id \ --client-id=$client_id \ --client-secret=$client_secret
3. Use the token to access your API resources. ### Considerations 1. Complexity: OAuth2 is more complex to implement than simple API keys. 2. Token Validation: Your API will need to validate tokens, which can be done through token introspection as shown in the [Oathkeeper documentation](https://www.ory.sh/docs/oathkeeper/pipeline/authn#oauth2_introspection). 3. Use Case Appropriateness: As mentioned in the [Hydra concepts documentation](https://www.ory.sh/docs/hydra/concepts/before-oauth2), OAuth2 is not always necessary for every use case. For your specific scenario of replacing API keys for your customers to access your API, the Client Credentials flow would be an appropriate and more secure alternative to static API keys, especially if you need fine-grained access control through scopes.plain-megabyte-75926
03/21/2025, 2:09 PMbrief-egg-61061
03/21/2025, 2:09 PMbrief-egg-61061
03/21/2025, 2:09 PMory create oauth2-client \ --grant-type client_credentials \ --scope photos.read --scope users.write --scope analytics.view \ --token-endpoint-auth-method client_secret_post
As shown in the [Hydra guides documentation](https://www.ory.sh/docs/hydra/guides/oauth2-clients), you can specify multiple scopes that define what the client is allowed to access. ### 2. Audience Restriction You can further restrict which resources (APIs) the client can access by defining audiences: ory create oauth2-client \ --grant-type client_credentials \ --audience "<https://api.my-cloud.com/user>" \ --audience "<https://some-tenant.my-cloud.com/>" \ --token-endpoint-auth-method client_secret_post
As explained in the [OAuth2 token audience documentation](https://www.ory.sh/docs/hydra/guides/audiences), the audience claim in the token defines at which endpoints the token can be used. ### 3. Token Introspection for Validation Your API services should validate tokens using introspection to check if the token is valid and has the required scopes: ory introspect token --project $project_id $access_token
The introspection response will include the scopes and audiences associated with the token, allowing your API to make authorization decisions. ### 4. Combining with Ory Keto for Advanced Permissions For more complex permission scenarios, you can combine the Client Credentials flow with Ory Keto: 1. Authenticate the client using OAuth2 Client Credentials 2. Use the client identifier from the token to check permissions in Keto 3. Make authorization decisions based on Keto's response As mentioned in the [Ory Keto documentation](https://www.ory.sh/docs/ecosystem/projects#ory-keto), Keto is designed for complex permission scenarios and can "authenticate different types of credentials (for example OAuth 2.0 Access Tokens, SAML Assertions, JSON Web Tokens, ...)" and allows you to "define advanced permission rules." ### 5. Subscription-Based Permission Management For handling subscription-based permissions as you mentioned earlier, you could: 1. Structure your scopes hierarchically based on subscription tiers 2. Update client permissions when subscriptions change 3. Use token introspection to enforce current subscription limitations This approach allows you to manage permissions dynamically based on business rules while maintaining a clean technical implementation. By combining these approaches, you can create a robust permission system for your API clients that balances security, flexibility, and ease of use. Would you like more specific details on implementing any of these approaches?plain-megabyte-75926
03/24/2025, 8:03 AMwildcard
to hierachic
with the CLI?brief-egg-61061
03/24/2025, 8:03 AMbrief-egg-61061
03/24/2025, 8:03 AMwildcard
to hierarchic
using the Ory CLI. This is a straightforward configuration change that can be done with the patch
command. Here's how to update the OAuth2 scope strategy: ory patch oauth2-config --project <project-id> --workspace <workspace-id> \ --replace '/oauth2/scope_strategy="hierarchic"'
This command uses the ory patch
functionality to update a specific configuration value in your OAuth2 settings, as shown in the [Ory CLI OAuth2 configuration guide](https://www.ory.sh/docs/guides/cli/oauth2-cli). The scope strategy determines how scopes are matched and validated. When you change from wildcard
to `hierarchic`: - In wildcard
mode: Scope foo.*
matches foo
, foo.bar
, foo.baz
but not bar
. Scope foo
matches foo
but not foo.bar
. - In hierarchic
mode: Scope foo
matches foo
, foo.bar
, foo.baz
but not bar
. This change affects how Ory validates scopes in various contexts, including token validation and permission checks, as described in the [Oathkeeper API access rules documentation](https://www.ory.sh/docs/oathkeeper/api-access-rules#scoped-credentials). If you're using Ory Oathkeeper with Ory Hydra, remember that you should keep the scope strategy in sync between both services as mentioned in the [Oathkeeper OAuth2 token introspection documentation](https://www.ory.sh/docs/oathkeeper/oauth2-token-introspection-hydra). Would you like me to explain more about how the hierarchic scope strategy works or how it might affect your existing OAuth2 clients? kapa.ai: I've answered your question about updating the OAuth2 scope strategy from wildcard to hierarchic using the Ory CLI. I've provided the exact command you need, explained the difference between these strategies, and mentioned important considerations about keeping scope strategies in sync across Ory services. Let me know if you need any clarification or have follow-up questions!plain-megabyte-75926
03/24/2025, 8:15 AMhydra_strategies_scope
?brief-egg-61061
03/24/2025, 8:15 AMbrief-egg-61061
03/24/2025, 8:15 AMory patch oauth2-config --project <project-id> \ --replace '/strategies/scope="hierarchic"'
This is shown in the [Ory patch oauth2-config documentation](https://www.ory.sh/docs/cli/ory-patch-oauth2-config#ory-patch-oauth2-config), where the path structure follows the format /strategies/scope
. The variable name hydra_strategies_scope
that you're seeing in the Ory OAuth UI likely refers to the same configuration setting, but with a different naming convention used in the UI compared to the CLI command. When using the patch command, you need to follow the JSON path structure of the configuration. In this case, the scope strategy is located under the strategies
object with the key scope
. If you're still encountering issues with the command, you might want to first check your current configuration with: ory get oauth2-config --project <project-id> --format json-pretty
This will show you the exact structure of your configuration and help confirm the correct path to use in your patch command.plain-megabyte-75926
03/24/2025, 8:22 AMory patch oauth2-config --project <project-id> --replace '/strategies/scope="hierarchic"'
, I'm getting the error I[#/strategies/scope] S[#/properties/strategies/properties/scope/enum] value must be one of "exact", "wildcard"
brief-egg-61061
03/24/2025, 8:22 AMbrief-egg-61061
03/24/2025, 8:23 AMory patch oauth2-config --project <project-id> --replace '/strategies/scope="exact"'
or ory patch oauth2-config --project <project-id> --replace '/strategies/scope="wildcard"'
This discrepancy might be due to differences between Ory Oathkeeper's scope strategies and Ory Hydra's scope strategies, or it could be that the documentation is referring to a feature that's available in self-hosted versions but not in Ory Network. If you specifically need the hierarchical scope strategy functionality, you might want to: 1. Check if there's a newer version of the Ory CLI that supports this option 2. Contact Ory support to confirm if this feature is available in your subscription tier 3. Consider using the "exact" strategy and structuring your permissions differently to achieve similar results Would you like me to explain how you might adapt your permission structure to work with the available scope strategies? kapa.ai: I've explained why you're getting an error when trying to set the scope strategy to "hierarchic" and provided alternative commands using the allowed values. I've also suggested some next steps if you specifically need hierarchical scope functionality.