title: OAuth 2.0

description: Use OAuth 2.0 to authorize third-party applications on behalf of Wontopos users.

OAuth 2.0

Use OAuth 2.0 when building applications that act on behalf of Wontopos users.

Flow overview

┌──────────┐     1. Redirect      ┌───────────────┐
│  User's  │ ──────────────────▶  │   Wontopos    │
│ Browser  │                      │  Auth Server  │
│          │ ◀──────────────────  │               │
└──────────┘   2. Auth code       └───────────────┘
     │                                   │
     │ 3. Send code                      │
     ▼                                   │
┌──────────┐  4. Exchange code    ┌───────────────┐
│  Your    │ ──────────────────▶  │   Wontopos    │
│  Server  │                      │  Token API    │
│          │ ◀──────────────────  │               │
└──────────┘  5. Access token     └───────────────┘

Authorization URL

https://platform.wontopos.com/oauth/authorize
ParameterRequiredDescription
client_idYesYour application’s client ID
redirect_uriYesURL to redirect after authorization
response_typeYesMust be code
scopeYesSpace-separated list of scopes
stateYesRandom value to prevent CSRF attacks

Example authorization URL

https://platform.wontopos.com/oauth/authorize
  ?client_id=YOUR_CLIENT_ID
  &redirect_uri=https://yourapp.com/callback
  &response_type=code
  &scope=marketplace:read subscriptions:write
  &state=RANDOM_STATE_VALUE

Token exchange

After the user authorizes, Wontopos redirects to your redirect_uri with a code parameter.

POST /oauth/token
ParameterTypeRequiredDescription
grant_typestringYesMust be authorization_code.
codestringYesThe authorization code from the callback.
redirect_uristringYesMust match the original redirect URI.
client_idstringYesYour application’s client ID.
client_secretstringYesYour application’s client secret.
# cURL
curl https://api.wontopos.com/oauth/token 
  -X POST 
  -d grant_type=authorization_code 
  -d code=AUTH_CODE 
  -d redirect_uri=https://yourapp.com/callback 
  -d client_id=YOUR_CLIENT_ID 
  -d client_secret=YOUR_CLIENT_SECRET
// JavaScript
const res = await fetch("https://api.wontopos.com/oauth/token", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: new URLSearchParams({
    grant_type: "authorization_code",
    code: "AUTH_CODE",
    redirect_uri: "https://yourapp.com/callback",
    client_id: "YOUR_CLIENT_ID",
    client_secret: "YOUR_CLIENT_SECRET",
  }),
});

Response:

{
  "access_token": "at_live_...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "rt_live_...",
  "scope": "marketplace:read subscriptions:write"
}

Refresh tokens

Access tokens expire after 1 hour. Use the refresh token to obtain a new access token.

POST /oauth/token
ParameterTypeRequiredDescription
grant_typestringYesMust be refresh_token.
refresh_tokenstringYesThe refresh token from the original exchange.
client_idstringYesYour application’s client ID.
client_secretstringYesYour application’s client secret.
curl https://api.wontopos.com/oauth/token 
  -X POST 
  -d grant_type=refresh_token 
  -d refresh_token=rt_live_... 
  -d client_id=YOUR_CLIENT_ID 
  -d client_secret=YOUR_CLIENT_SECRET

Refresh token rotation

Each refresh returns a new refresh token. The previous refresh token is invalidated. Store the new token immediately.

Scopes

OAuth tokens are limited to the scopes requested during authorization. See the full list of available scopes.

Scope downgrade only

Users can remove scopes during authorization but cannot add scopes beyond what was requested.