Exchange an OIDC token for a ZapWorks token
const url = 'https://example.com/v1/auth/token';const options = { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: new URLSearchParams({ grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange', subject_token: 'example', subject_token_type: 'urn:ietf:params:oauth:token-type:id_token', requested_token_type: 'urn:ietf:params:oauth:token-type:access_token' })};
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://example.com/v1/auth/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data grant_type=urn:ietf:params:oauth:grant-type:token-exchange \ --data subject_token=example \ --data subject_token_type=urn:ietf:params:oauth:token-type:id_token \ --data requested_token_type=urn:ietf:params:oauth:token-type:access_tokenExchanges a token from an OIDC provider that ZapWorks trusts for a ZapWorks token, which can then be used to call the rest of the API. It follows OAuth 2.0 Token Exchange (RFC 8693), so OAuth client libraries can call it directly. It needs no Authorization header.
Request Bodyrequired
Section titled “Request Bodyrequired”object
The token from the OIDC provider.
What kind of token subject_token is - usually an ID token.
The kind of token wanted. Only access tokens are issued.
object
The token from the OIDC provider.
What kind of token subject_token is - usually an ID token.
The kind of token wanted. Only access tokens are issued.
Responses
Section titled “Responses”The ZapWorks token
object
The ZapWorks token.
How many seconds the token is valid for.
Example
{ "issued_token_type": "urn:ietf:params:oauth:token-type:access_token", "token_type": "Bearer"}The request is invalid
An error in the form OAuth token endpoints use.
object
The kind of error, e.g. invalid_request or unsupported_grant_type.
Example generated
{ "error": "example", "error_description": "example"}Exchanging tokens isn’t available yet
An error in the form OAuth token endpoints use.
object
The kind of error, e.g. invalid_request or unsupported_grant_type.
Example generated
{ "error": "example", "error_description": "example"}