gifted-agent-33940
04/17/2025, 9:01 PMbrief-egg-61061
04/17/2025, 9:01 PMbrief-egg-61061
04/17/2025, 9:02 PMclient_credentials
grant type: hydra create oauth2-client \ --name "M2M Client" \ --grant-type client_credentials \ --scope your_scope1,your_scope2
2. You can then use this client to perform the OAuth2 Client Credentials flow and receive an access token. [Hydra CLI documentation](https://www.ory.sh/docs/hydra/cli/hydra-create-oauth2-client#hydra-create-oauth2-client) provides more details on creating OAuth2 clients with specific parameters. ## Device Flow For the Device Flow (useful for devices with limited input capabilities like smart TVs): 1. Create an OAuth2 client with the urn:ietf:params:oauth:grant-type:device_code
grant type: hydra create oauth2-client \ --name "Device Flow Client" \ --grant-type "urn:ietf:params:oauth:grant-type:device_code" \ --scope your_scope1,your_scope2
The Device Flow is designed for devices that have limited inputs or do not have a web browser, allowing users to authorize applications on such devices to access their accounts by initiating the flow on a separate device. ## Usage Examples For M2M authentication, after creating the client, you can exchange the client credentials for an access token as described in the [Run your own OAuth2 Server blog post](https://www.ory.sh/blog/run-oauth2-server-open-source-api-security). For more information on when to use these flows: - M2M is ideal for server-to-server communication where user interaction isn't needed - Device Flow is best for smart devices, TVs, or game consoles with limited input capabilities You can find more details about OAuth2 use cases in the [OAuth2 fundamentals documentation](https://www.ory.sh/docs/oauth2-oidc/overview/oauth2-concepts#use-case-examples).gifted-agent-33940
04/17/2025, 9:02 PMgifted-agent-33940
04/17/2025, 9:03 PMbrief-egg-61061
04/17/2025, 9:03 PMbrief-egg-61061
04/17/2025, 9:04 PMbash # Linux bash <(curl <https://raw.githubusercontent.com/ory/meta/master/install.sh>) -d -b . hydra <version-you-want> # macOS brew install ory/tap/hydra # Windows scoop bucket add ory <https://github.com/ory/scoop.git> scoop install hydra # Docker docker pull oryd/hydra:<version-you-want>
[Hydra Self-hosted Installation](https://www.ory.sh/docs/hydra/self-hosted/install) ## Enabling M2M (Client Credentials Flow) To enable the Client Credentials flow in open source Hydra: 1. Create an OAuth2 client with the client_credentials grant type: bash hydra create oauth2-client \ --name "Client Credentials Demo" \ --grant-type client_credentials
2. Use the client ID and secret to perform the OAuth2 Client Credentials flow: bash hydra perform client-credentials \ --client-id=<your-client-id> \ --client-secret=<your-client-secret>
3. You can validate the token using introspection: bash hydra introspect token <access-token>
[Run your own OAuth2 Server](https://www.ory.sh/blog/run-oauth2-server-open-source-api-security) ## Enabling Device Flow For Device Flow in open source Hydra: 1. Create an OAuth2 client with the device code grant type: bash hydra create oauth2-client \ --name "Device Flow Client" \ --grant-type "urn:ietf:params:oauth:grant-type:device_code"
Both of these flows are fully supported in the open source version of Ory Hydra, and you don't need to purchase any enterprise product to use them. If you encounter any issues during setup, you can get help from the community through: - [Ory Hydra GitHub Discussions](https://github.com/ory/hydra/discussions) - [Ory Community Slack](https://www.ory.sh/chat) [Welcome to Ory!](https://www.ory.sh/docs/welcome#need-help)gifted-agent-33940
04/17/2025, 9:05 PMbrief-egg-61061
04/17/2025, 9:05 PMbrief-egg-61061
04/17/2025, 9:05 PMbash curl -X POST '<https://your-hydra-instance/oauth2/device/auth>' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'client_id=YOUR_CLIENT_ID&scope=openid offline'
This request will return a JSON response containing: - `device_code`: The verification code for the device - `user_code`: The code the user needs to enter on another device - `verification_uri`: The URL where the user should go to enter the code - `verification_uri_complete`: A URL that includes the user code - `expires_in`: The lifetime of the codes in seconds - `interval`: How often the device should poll for completion The API specification for this endpoint is documented in the [Hydra API Reference](https://www.ory.sh/docs/hydra/reference/api). After initiating the flow, the user would go to the verification_uri
on another device, enter the user_code
, and authorize the application. Meanwhile, your device would poll the token endpoint to check if authorization has been granted. Note that as mentioned in the documentation: "This endpoint is not documented here because you should never use your own implementation to perform OAuth2 flows. OAuth2 is a very popular protocol and a library for your programming language will exist." While you can use curl for testing, in production it's recommended to use an OAuth2 library for your programming language. For more information on the Device Flow, you can refer to [RFC 8628](https://tools.ietf.org/html/rfc8628) which is the official specification. [Hydra API Reference](https://www.ory.sh/docs/hydra/reference/api)gifted-agent-33940
04/18/2025, 7:17 PMbrief-egg-61061
04/18/2025, 7:17 PMbrief-egg-61061
04/18/2025, 7:17 PMgifted-agent-33940
05/02/2025, 6:33 PMbrief-egg-61061
05/02/2025, 6:33 PMbrief-egg-61061
05/02/2025, 6:33 PMgifted-agent-33940
05/02/2025, 6:34 PMbrief-egg-61061
05/02/2025, 6:34 PMbrief-egg-61061
05/02/2025, 6:34 PM