English
English
Appearance
English
English
Appearance
https://api.repliz.com/public/oauth/tokenExchanges the code from the authorize page for an access token and a refresh token, or trades a refresh token for new ones. Part of Login with Repliz.
client_id and client_secret, in the body or as Basic Auth (Authorization: Basic Base64(client_id:client_secret)). A public app sends only client_id.application/x-www-form-urlencoded or application/json| Field | Type | Required | Description |
|---|---|---|---|
grant_type | string | Yes | authorization_code |
code | string | Yes | The code Repliz added to your redirect URI. It works once, within 5 minutes. |
redirect_uri | string | Yes | The same redirect_uri you sent to the authorize page. |
code_verifier | string | Yes | The PKCE verifier whose SHA-256 you sent as code_challenge. 43 to 128 characters. |
client_id | string | Yes | Client ID of your app. Can go in the Basic Authorization header instead. |
client_secret | string | Confidential apps | Client secret of your app. Can go in the Basic Authorization header instead. Public apps leave it out. |
| Field | Type | Required | Description |
|---|---|---|---|
grant_type | string | Yes | refresh_token |
refresh_token | string | Yes | The refresh_token of the last token response. Each refresh returns a new one; the old one stops working. |
client_id | string | Yes | Client ID of your app. |
client_secret | string | Confidential apps | Client secret of your app. |
The scopes stay the ones the user allowed. To ask for more, send the user to the authorize page again.
curl -X POST "https://api.repliz.com/public/oauth/token" \
-u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
-d grant_type=authorization_code \
-d code=CODE_FROM_REDIRECT \
-d redirect_uri=https://example.com/callback \
-d code_verifier=YOUR_CODE_VERIFIERimport axios from 'axios';
const response = await axios.post(
'https://api.repliz.com/public/oauth/token',
new URLSearchParams({
grant_type: 'authorization_code',
code: 'CODE_FROM_REDIRECT',
redirect_uri: 'https://example.com/callback',
code_verifier: 'YOUR_CODE_VERIFIER',
client_id: 'YOUR_CLIENT_ID',
client_secret: 'YOUR_CLIENT_SECRET',
}),
);
console.log(response.data);const response = await fetch('https://api.repliz.com/public/oauth/token', {
method: 'POST',
body: new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: 'YOUR_REFRESH_TOKEN',
client_id: 'YOUR_CLIENT_ID',
client_secret: 'YOUR_CLIENT_SECRET',
}),
});
const data = await response.json();
console.log(data);{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6ImF0K2p3dCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "rplz_rt_Vb1k3nQ8sXo2yZ7pL4mR9tA6cE0wF5hJ8uI2oP3qS1d",
"scope": "profile schedule:write"
}{
"error": "invalid_grant",
"error_description": "invalid or expired code"
}{
"error": "invalid_client",
"error_description": "invalid client_secret"
}{
"code": 429,
"message": "too many token requests, try again in a minute"
}| Field | Type | Description |
|---|---|---|
access_token | string | Send it as Authorization: Bearer <access_token> to the Public API. Valid for 1 hour. |
token_type | string | Always Bearer. |
expires_in | number | Seconds until the access token expires, 3600. |
refresh_token | string | Trade it here for new tokens. Valid for 30 days after its last use; store it on your server. |
scope | string | The scopes the user allowed, separated by spaces. profile is always included. |
The response has Cache-Control: no-store.
Errors follow the OAuth 2.0 format, error with a code and error_description with the reason:
error | Status | When |
|---|---|---|
invalid_request | 400 | A field is missing, or code_verifier isn't 43 to 128 characters of A-Z, a-z, 0-9, -, ., _, ~. |
invalid_client | 401 | Unknown client_id, a wrong or missing client_secret for a confidential app, or an app Repliz disabled (this app is disabled). |
invalid_grant | 400 | The code or refresh token is used, expired, revoked, or from another app, the redirect_uri differs, or the PKCE check fails. |
unsupported_grant_type | 400 | grant_type is neither authorization_code nor refresh_token. |
A code is used up by its first try, even a failed one: send the user to the authorize page again.
Refresh tokens are single-use
Save the new refresh_token of every response. If an old refresh token is sent again more than a minute after it was replaced, Repliz treats it as stolen and disconnects the app: the user has to allow it again.