ApiSkills

Authentication · 12 min

OAuth2 client credentials (n8n)

The machine-to-machine grant n8n uses most: exchange your credentials for a short-lived token.

OAuth2 client credentials is the standard way one server talks to another. Your app exchanges its client_id + client_secret for a short-lived access token (a JWT), then calls the API with that token. No user is involved.

The flow by hand

# 1. Get a token
curl -X POST https://api.ifsjaipur.cloud/oauth/token \
  -u "APP_ID:APP_SECRET" \
  -d "grant_type=client_credentials&scope=stocks:read"
# -> { "access_token": "...", "token_type": "Bearer", "expires_in": 3600, "scope": "stocks:read" }

# 2. Use it
curl "https://api.ifsjaipur.cloud/playground/data/stocks/candles?shape=flat&page_size=5" \
  -H "Authorization: Bearer ACCESS_TOKEN"

Setting it up in n8n (step by step)

  1. Create a new credential of type "OAuth2 API".
  2. Grant Type: Client Credentials.
  3. Access Token URL: https://api.ifsjaipur.cloud/oauth/token
  4. Client ID: your App ID. Client Secret: your App Secret.
  5. Scope: stocks:read (or fpa:read).
  6. Authentication: try "Body" first; if the token request fails, switch to "Header (Basic Auth)". Both are accepted.
  7. Save. Then on the HTTP Request node set Authentication = Generic Credential Type → OAuth2 API, and point the URL at a data endpoint.
SettingValue
Grant TypeClient Credentials
Access Token URLhttps://api.ifsjaipur.cloud/oauth/token
Client IDyour App ID
Client Secretyour App Secret
Scopestocks:read
  • Scope must be one your app was granted — read scopes (fpa:read, stocks:read) are granted automatically. Leave scope blank to get all granted scopes.
  • The access token is a JWT that expires in 1 hour; n8n refreshes it automatically.
  • invalid_client → wrong Client ID/Secret. invalid_scope → you asked for a scope you were not granted.

Tip · This ties everything together: the token you get here is a JWT (the JWT lesson) and you present it as a Bearer token (the Bearer lesson).