Skip to content

Generate Authentication Code



POST /api/v1/offline_token/temporary_auth_code/create

Overview

Creates a short-lived, one-time authentication code for the current workspace, for the frontend to redeem as a temporary offline access token.

Prerequisites and Usage Steps

Submit expires and the optional roles. The endpoint returns authCode and does not return the token directly; pass code as-is to the frontend authentication entry point on the same site, where the frontend service redeems it via GET /api/v1/auth-token/get?authCode=.... Alternatively, following the console's existing integration convention, open /redirect_auth/{authCode}?overwrite=true&to=xxx: the intermediate page consumes code, overwrite=true overwrites the current login state, and omitting it is for temporary use; to is the URL-encoded site-relative address. The console domain and the frontend API domain should be selected according to the same-site integration address. After a successful redemption, code is deleted immediately and cannot be reused; for concurrent redemption and revocation, only one flow is allowed to consume it. Do not use authCode as DF-API-KEY, X-FT-Auth-Token, or an offline token to call business APIs directly. expires is the requested lifetime of the access token, in seconds; the deadline is counted from the moment the code is created, and redemption does not restart the timer. The actual value is the smaller of the request and the site token limit. The expiresIn of the code itself defaults to 600 seconds and is determined by the site configuration; it differs from expires. If the token request lifetime expires first, the code cannot be redeemed even if the code cache still exists. Verify the role list item by item against the current workspace roles first; creating a code does not fully validate each role, nor does it prove that you have the target access permissions. Role permissions are computed and cached when the token is redeemed, and subsequent permission changes are not guaranteed to update already-issued tokens automatically. Unused codes can be revoked by calling Revoke One-Time Authentication Code; for the validity period and revocation boundary of redeemed tokens, see below.

Request Headers

Parameter Name Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the workspace.
Example: <DF-API-KEY>
How to obtain or fill in: Obtain an OpenAPI Key with this operation permission from API Key Management in the target workspace.

Body Parameters

Parameter Name Type Required Description
roles array Optional array of role UUIDs. If omitted or [], the default is the shared sharing access identity; it is not readOnly by default. There is currently no strict per-role validity check; the client must verify first.
Null allowed: False
Example: ["readOnly"]
How to obtain or fill in: Obtain the target role in the same workspace from content.data[].uuid in Role List, for example wsAdmin/general/readOnly or role_ custom role; choose according to the minimum access requirement.
roles[*] string Conditionally required A single non-null role identifier string.
Null allowed: False
Example: readOnly
How to obtain or fill in: Copy a single role UUID from Role List; do not enter the display name.
expires integer Y Required. Requested lifetime of the access token, from 1 to 604800 seconds; the actual value is also constrained by the site limit. Timing starts when the code is created; this does not control the code's own TTL.
Null allowed: False
$maxValue: 604800
$minValue: 1
Example: 3600
How to obtain or fill in: Choose the number of seconds according to the actual access task, for example 3600 for 1 hour; short tasks should use a shorter lifetime.

Additional Parameter Notes

Subsequent redemption is handled by the frontend service: GET <FrontEndpoint>/api/v1/auth-token/get?authCode=<authCode returned at creation>. On success, content contains token, tokenType=custom, workspaceUUID, and expiresAt (Unix seconds), where expiresAt is the final access deadline. That redemption response does not belong to this creation endpoint; a failed redemption may be 400 ft.NotFoundAuthCode, 401 ft.OfflineTokenExpired, or a workspace error. Expiry or revocation of a code affects only codes that have not yet been redeemed and does not revoke previously redeemed tokens; the current legacy revoke token endpoint has compatibility limitations for new-version tokens, so confirm according to the notes on the relevant page.

Request Example

curl --request POST 'https://openapi.guance.com/api/v1/offline_token/temporary_auth_code/create' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"roles":["readOnly"],"expires":3600}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content.authCode string One-time authentication code; it must be passed as-is to the same-site frontend authentication redemption entry point; do not parse it apart or concatenate it yourself.
content.action string Fixed value offline_custom_token, indicating a one-time code that can be redeemed for a custom offline token.
content.workspaceUUID string UUID of the workspace to which the API Key belongs; this is also the subsequent access scope.
content.expiresIn integer Validity duration of the code itself, in seconds, default 600; this is not the access lifetime of the final token.
content.declaration object or null Public declaration of the workspace.
{
  "code": 200,
  "content": {
    "authCode": "AUTH-CODE-EXAMPLE.1785430800",
    "action": "offline_custom_token",
    "workspaceUUID": "wksp_example",
    "expiresIn": 600,
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

An invalid role is not guaranteed to return a role-not-found error at creation time. After successful creation, you must still verify actual access through the redemption result and the permission checks of the target interface. This applies only to the workspace of the current API Key; no single-resource allowlist parameter is provided.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed A request field is missing, or a field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError The request JSON syntax is invalid Request JSON format error Fix the JSON according to content.reason, line, and column.
400 ft.JsonFormatError The JSON top level is not an object Some json file format errors Submit a single JSON object.
401 ft.WKSPNotExistOrReleased A real-time check at creation finds that the workspace has been deleted or released Workspace does not exist / has been released Check whether the workspace to which the API Key belongs is valid.
500 ft.InternalServerError Cache or other internal processing failure Internal error Keep the traceId and contact the administrator to verify the result; avoid automatically repeating authorization or concluding that revocation has completed based on the error.

Feedback

Is this page helpful?