Exchange device code or refresh token
Exchange device code or refresh token: deviceToken in the TypeScript, Python, Rust and Go clients.
POST /v1/auth/device/token
Exchanges an authorized device code or a refresh token for an access token and rotating refresh token. Accepts JSON and form-encoded bodies. While polling, wait at least interval seconds and increase the interval on slow_down. Store the new refresh token after every successful grant.
photon.auth.device.token(input: DeviceTokenInput, options?: RequestOptions): Promise<DeviceTokenOutput>photon.auth.device.token(input: DeviceTokenInput, *, options: RequestOptions | None = None) -> models.DeviceTokenResponseclient.device_token(body: &types::DeviceTokenRequest).await -> Result<ResponseValue<types::DeviceTokenResponse>, Error<DeviceTokenError>>client.Auth.Device.Token(ctx context.Context, params *DeviceTokenParams, opts ...RequestOption) (*DeviceTokenResponse, error)import { Photon } from "@photon-ai/api";
const photon = new Photon();
const result = await photon.auth.device.token({
body: {
device_code: "device_code",
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
},
});from photon_api import Photon
from photon_api.rpc_generated import DeviceTokenInput
photon = Photon()
result = photon.auth.device.token(
DeviceTokenInput.model_validate({
"body": {
"device_code": "device_code",
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
},
})
)use photon_ai_api::PhotonClientBuilder;
let client = PhotonClientBuilder::new().build()?;
let result = client
.device_token(
&serde_json::from_value(serde_json::json!({
"device_code": "device_code",
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
}))?,
)
.await
.map_err(|error| format!("{error:?}"))?
.into_inner();import (
"context"
"encoding/json"
photonapi "github.com/photon-hq/api/packages/go"
)
ctx := context.Background()
client := photonapi.NewClient()
var body photonapi.DeviceTokenRequest
if err := json.Unmarshal([]byte(`{
"device_code": "device_code",
"grant_type": "urn:ietf:params:oauth:grant-type:device_code"
}`), &body); err != nil {
return err
}
result, err := client.Auth.Device.Token(ctx, &photonapi.DeviceTokenParams{
Body: body,
})
if err != nil {
return err
}
_ = result{
"access_token": "string",
"authentication_method": "string",
"expires_in": 0,
"refresh_token": "string",
"user": {
"email": "string",
"first_name": null,
"id": "string",
"last_name": null
}
}Body
One of: DeviceCodeGrantRequest
device_code returned by POST /v1/auth/device/code. Required for a device-code grant.
Selects the device authorization grant to poll or exchange a device code.
One of: RefreshTokenGrantRequest
Selects the refresh-token grant to obtain a new token pair.
Most recently issued refresh token. Required for a refresh grant; replace it with the returned refresh_token after success.
Returns
200 Token pair (snake_case OAuth wire format). Body (form-encoded or JSON): grant_type=urn:ietf:params:oauth:grant-type:device_code with device_code, or grant_type=refresh_token with refresh_token. Refresh tokens rotate on every grant — always store the new one. DeviceTokenResponse
Bearer access token for authenticated Photon API requests.
Authentication method used for the device login, when returned. Omitted for refresh grants.
Access-token validity in seconds, derived from its expiry and issue times; defaults to 300 when unavailable.
Refresh token for the next refresh grant. Tokens rotate on every grant; replace the stored value with this one.
Profile of the authenticated user.