Device Authorization
OAuth device authorization flow for CLI and TV clients.
This page documents the current Ruby port behavior. Ruby uses snake_case option names and auth.api method names; HTTP paths and JSON keys keep the upstream wire shape where implemented.
Configure
require "better_auth"
auth = BetterAuth.auth(
secret: ENV.fetch("BETTER_AUTH_SECRET"),
base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
plugins: [
BetterAuth::Plugins.device_authorization
]
)Usage
issued = auth.api.device_code(body: { client_id: "cli", scope: "openid profile" })
auth.api.device_approve(headers: { "cookie" => request.env["HTTP_COOKIE"] }, body: { user_code: issued[:user_code] })
token = auth.api.device_token(body: { grant_type: "urn:ietf:params:oauth:grant-type:device_code", device_code: issued[:device_code], client_id: "cli" })Routes
| Method | Path | Ruby API method |
|---|---|---|
POST | /device/code | auth.api.device_code |
POST | /device/token | auth.api.device_token |
GET | /device | auth.api.device_verify |
POST | /device/approve | auth.api.device_approve |
POST | /device/deny | auth.api.device_deny |
Options
Current Ruby options accepted by BetterAuth::Plugins.device_authorization:
validate_clientgenerate_device_codedevice_code_lengthgenerate_user_codeuser_code_lengthexpires_inintervalon_device_auth_requestverification_uri
Support Notes
- The examples above are based on Ruby plugin source and tests in
packages/better_auth. - If an upstream section is not represented here, treat it as not yet documented or not yet supported by the Ruby port until the matching Ruby implementation exists.