Redeem a device code for an API key (RFC 8628 token endpoint)
const url = 'https://api.legesher.io/v1/oauth/token';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"client_id":"example","device_code":"example","grant_type":"urn:ietf:params:oauth:grant-type:device_code"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.legesher.io/v1/oauth/token \ --header 'Content-Type: application/json' \ --data '{ "client_id": "example", "device_code": "example", "grant_type": "urn:ietf:params:oauth:grant-type:device_code" }'Poll for approval; on success the access token is a fresh API key.
Poll outcomes (HTTP 400, OAuth error body): authorization_pending
(keep polling), slow_down (add 5 seconds to the interval; a poll
that comes too early also restarts the wait), expired_token /
access_denied
(terminal: restart the flow), invalid_grant (unknown, malformed, or
already-redeemed code).
Request Bodyrequired
Section titled “ Request Bodyrequired ”object
Accepted and ignored: there is no client registry.
The device_code from POST /v1/oauth/device.
Must be the RFC 8628 device-code grant URN.
object
Accepted and ignored: there is no client registry.
The device_code from POST /v1/oauth/device.
Must be the RFC 8628 device-code grant URN.
Responses
Section titled “ Responses ”Successful Response
RFC 6749 §5.1 access-token response (successful device redemption).
The access token is a newly created Legesher API key: use it as
Authorization: Bearer <token> like any other key. It does not
expire and there is no refresh token; revoke it with
POST /v1/oauth/revoke.
object
A newly minted API key (lgsh_live_…). Shown exactly once.
Always ‘bearer’.
Example
{ "token_type": "bearer"}Headers
Section titled “ Headers ”Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
OAuth error (RFC 6749 §5.2 / RFC 8628 §3.5): authorization_pending, slow_down, expired_token, access_denied, invalid_grant, invalid_request, or unsupported_grant_type.
RFC 6749 §5.2 / RFC 8628 §3.5 error body (HTTP 400).
error values used by this API: authorization_pending,
slow_down, expired_token, access_denied, invalid_grant,
invalid_request, unsupported_grant_type.
object
Example generated
{ "error": "example", "error_description": "example"}Headers
Section titled “ Headers ”Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Request body over the ceiling.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Too many requests. Wait before retrying.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.