API reference
OAuth
Exchanging and refreshing the tokens minted by the user consent flow.
Exchange or refresh tokens
post/oauth/token
Authenticate with your partner API key and the Twofold-Client-Id header.
Request bodyform-encoded
client_idstringYour partner id. Optional only in the sense that the Twofold-Client-Id header carries the same value - one of the two is required, and if you send both they must match.
grant_typeenumrequiredauthorization_code exchanges a consent-flow code; refresh_token rotates an existing pair.
authorization_coderefresh_token
codestringThe authorization code from the consent redirect. Required for grant_type=authorization_code; single-use, expires 10 minutes after consent.
redirect_uristringMust exactly match the redirect_uri the authorization request used. Required for grant_type=authorization_code.
code_verifierstringThe PKCE verifier whose S256 hash was sent as code_challenge. Required for grant_type=authorization_code.
refresh_tokenstringThe current refresh token. Required for grant_type=refresh_token; rotated on every use.
Response200
A freshly minted access/refresh token pair. Refreshing rotates both.
access_tokenstringOpaque bearer token for /v2/users/* calls. Valid for 1 hour.
token_typeenumAlways Bearer.
Bearer
expires_inintegerAccess-token lifetime in seconds.
refresh_tokenstringOpaque refresh token, valid 90 days. Rotated on every refresh - always store the newest pair. Re-sending a superseded refresh token within 5 minutes of its rotation returns a fresh pair instead; after that it revokes the link.
scopeenumAlways full_access - the single scope.
full_access
Example request
curl -X POST https://partner-api.trytwofold.com/oauth/token \
-H "Authorization: Bearer twofold_key_prod_…" \
-H "Twofold-Client-Id: prtn_ab12Cd34Ef56" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=twofold_code_prod_…" \
--data-urlencode "redirect_uri=https://your-emr.example.com/oauth/callback" \
--data-urlencode "code_verifier=…"curl -X POST https://partner-api.staging.trytwofold.com/oauth/token \
-H "Authorization: Bearer twofold_key_staging_…" \
-H "Twofold-Client-Id: prtn_ab12Cd34Ef56" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=twofold_code_staging_…" \
--data-urlencode "redirect_uri=https://your-emr.example.com/oauth/callback" \
--data-urlencode "code_verifier=…"Example response
{
"access_token": "…",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "…",
"scope": "full_access"
}{
"access_token": "…",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "…",
"scope": "full_access"
}Errors
400The grant is invalid (invalid_grant: bad, expired, replayed or mismatched code / refresh token — a replay revokes the link itself, so link.revoked fires and the user must authorize again) or the request is malformed (invalid_request, unsupported_grant_type). Possible error values: invalid_request, invalid_grant, unsupported_grant_type.
401Client authentication failed — the partner API key or the Twofold-Client-Id header is missing, wrong or revoked. Possible error values: invalid_client.
403The client is authenticated but may not use this grant — production access is not open yet. Possible error values: unauthorized_client.
429Rate limit exceeded: the OAuth endpoints share the API key's budget of 100 requests/second (burst 200). Wait Retry-After seconds and retry. Possible error values: temporarily_unavailable.
500Something failed on Twofold's side, or the partner API is temporarily paused. Safe to retry. Possible error values: server_error, temporarily_unavailable.
Revoke a token
post/oauth/revoke
Authenticate with your partner API key and the Twofold-Client-Id header.
Request bodyform-encoded
client_idstringYour partner id. Optional only in the sense that the Twofold-Client-Id header carries the same value - one of the two is required, and if you send both they must match.
tokenstringrequiredThe access or refresh token to revoke. Revoking either revokes the link and all its tokens.
token_type_hintenumOptional RFC 7009 hint; accepted and ignored - both token types are looked up regardless.
access_tokenrefresh_token
Response200
The link is revoked. Also returned for tokens that don't exist (RFC 7009 §2.2).
Example request
curl -X POST https://partner-api.trytwofold.com/oauth/revoke \
-H "Authorization: Bearer twofold_key_prod_…" \
-H "Twofold-Client-Id: prtn_ab12Cd34Ef56" \
--data-urlencode "token=twofold_refresh_prod_…"curl -X POST https://partner-api.staging.trytwofold.com/oauth/revoke \
-H "Authorization: Bearer twofold_key_staging_…" \
-H "Twofold-Client-Id: prtn_ab12Cd34Ef56" \
--data-urlencode "token=twofold_refresh_staging_…"Errors
400The grant is invalid (invalid_grant: bad, expired, replayed or mismatched code / refresh token — a replay revokes the link itself, so link.revoked fires and the user must authorize again) or the request is malformed (invalid_request, unsupported_grant_type). Possible error values: invalid_request, invalid_grant, unsupported_grant_type.
401Client authentication failed — the partner API key or the Twofold-Client-Id header is missing, wrong or revoked. Possible error values: invalid_client.
403The client is authenticated but may not use this grant — production access is not open yet. Possible error values: unauthorized_client.
429Rate limit exceeded: the OAuth endpoints share the API key's budget of 100 requests/second (burst 200). Wait Retry-After seconds and retry. Possible error values: temporarily_unavailable.
500Something failed on Twofold's side, or the partner API is temporarily paused. Safe to retry. Possible error values: server_error, temporarily_unavailable.