Skip to main content

service_tokens

Creates, updates, deletes, gets or lists a service_tokens resource.

Overview

Nameservice_tokens
TypeResource
Idcloudflare.zero_trust.service_tokens

Fields

The following fields are returned by SELECT queries:

Get a service token response

NameDatatypeDescription
idstringUUID. (example: f174e90a-fafe-4643-bbbc-4a0ed4fc8415)
namestringThe name of the service token. (example: CI/CD token)
client_idstringThe Client ID for the service token. Access will check for this value in the CF-Access-Client-ID request header. (example: 88bf3b6d86161464f6509f7219099e57.access.example.com)
created_atstring (date-time) (example: 2014-01-01T05:20:00.12345Z)
durationstringThe duration for how long the service token will be valid. Must be in the format 300ms or 2h45m. Valid time units are: ns, us (or µs), ms, s, m, h. The default is 1 year in hours (8760h). (default: 8760h, example: 60m)
expires_atstring (date-time) (example: 2014-01-01T05:20:00.12345Z)
last_seen_atstring (date-time) (example: 2014-01-01T05:20:00.12345Z)
updated_atstring (date-time) (example: 2014-01-01T05:20:00.12345Z)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_by_accountselectservice_token_id, account_idFetches a single service token.
get_by_zoneselectservice_token_id, zone_idFetches a single service token.
list_by_accountselectaccount_idname, search, page, per_pageLists all service tokens.
list_by_zoneselectzone_idname, search, page, per_pageLists all service tokens.
create_by_accountinsertaccount_id, nameGenerates a new service token. Note: This is the only time you can get the Client Secret. If you lose the Client Secret, you will have to rotate the Client Secret or create a new service token.
create_by_zoneinsertzone_id, nameGenerates a new service token. Note: This is the only time you can get the Client Secret. If you lose the Client Secret, you will have to rotate the Client Secret or create a new service token.
update_by_accountreplaceservice_token_id, account_idUpdates a configured service token.
update_by_zonereplaceservice_token_id, zone_idUpdates a configured service token.
delete_by_accountdeleteservice_token_id, account_idDeletes a service token.
delete_by_zonedeleteservice_token_id, zone_idDeletes a service token.
refreshexecservice_token_id, account_idRefreshes the expiration of a service token.
rotateexecservice_token_id, account_idGenerates a new Client Secret for a service token and revokes the old one.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
account_idstringThe Cloudflare account ID.
service_token_idstring
zone_idstringThe Cloudflare zone ID.
namestring
pageinteger
per_pageinteger

SELECT examples

Fetches a single service token.

SELECT
id,
name,
client_id,
created_at,
duration,
expires_at,
last_seen_at,
updated_at
FROM cloudflare.zero_trust.service_tokens
WHERE service_token_id = '{{ service_token_id }}' -- required
AND account_id = '{{ account_id }}' -- required
;

INSERT examples

Generates a new service token. Note: This is the only time you can get the Client Secret. If you lose the Client Secret, you will have to rotate the Client Secret or create a new service token.

INSERT INTO cloudflare.zero_trust.service_tokens (
client_secret_version,
duration,
name,
previous_client_secret_expires_at,
account_id
)
SELECT
{{ client_secret_version }},
'{{ duration }}',
'{{ name }}' /* required */,
'{{ previous_client_secret_expires_at }}',
'{{ account_id }}'
RETURNING
errors,
messages,
result,
success
;

REPLACE examples

Updates a configured service token.

REPLACE cloudflare.zero_trust.service_tokens
SET
client_secret_version = {{ client_secret_version }},
duration = '{{ duration }}',
name = '{{ name }}',
previous_client_secret_expires_at = '{{ previous_client_secret_expires_at }}'
WHERE
service_token_id = '{{ service_token_id }}' --required
AND account_id = '{{ account_id }}' --required
RETURNING
errors,
messages,
result,
success;

DELETE examples

Deletes a service token.

DELETE FROM cloudflare.zero_trust.service_tokens
WHERE service_token_id = '{{ service_token_id }}' --required
AND account_id = '{{ account_id }}' --required
;

Lifecycle Methods

Refreshes the expiration of a service token.

EXEC cloudflare.zero_trust.service_tokens.refresh
@service_token_id='{{ service_token_id }}' --required,
@account_id='{{ account_id }}' --required
;