OAuth2 Authentication on the Yapla Platform
This article explains how to connect an application to the Yapla GraphQL API with OAuth2 and keep the connection active.
Get an access token (access_token) through the OAuth2 protocol to make secure calls to the Yapla GraphQL API on behalf of a user, then renew it automatically to keep your integration connected.
In this article
- Supported authentication flows
- Step 1: Get your OAuth client credentials
- Step 2: Redirect the user to the consent page
- Step 3: Exchange the authorization code for an access token
- Step 4: Use the access token
- Renew the access token
- Keep a connection active without a new authorization
Supported authentication flows
Yapla supports two standard and secure flows:
- Authorization Code Flow: ideal for traditional web applications, where the
Client Secretcan be stored securely on a server. - Authorization Code Flow with PKCE (Proof Key for Code Exchange): recommended for public clients, such as mobile applications or single-page applications (SPA), where the
Client Secretcannot be stored securely.
Step 1: Get your OAuth client credentials
Before connecting to the API, get a Client ID and, if needed, a Client Secret. These credentials are specific to your application.
Send an email to support@yapla.com with the following information:
- Application name: a descriptive name for your project.
- Client type: confidential (web server) or public (SPA, mobile application).
- Description of your needs: the intended use of your integration and the permissions (scopes) you think you need. Our team sends you the scopes that apply to your client based on this description.
- Redirect URIs: the full address or addresses to which Yapla redirects the user after authorization. These addresses must be exact and secure (
https).
Our team processes your request and securely sends you your Client ID (and your Client Secret, if applicable).
Step 2: Redirect the user to the consent page
First, redirect the user to the Yapla consent page.
A. Generate the code_verifier and code_challenge (PKCE only)
If you use the PKCE flow, first generate:
- A
code_verifier: a high-entropy random string. - A
code_challenge: thecode_verifierhashed with SHA-256, then Base64 URL encoded.code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
Keep the code_verifier: you need it in step 3.
B. Build the authorization URL
Build a URL in the following form:
https://login.yapla.com/oauth/authorize?response_type=code&client_id=[YOUR_CLIENT_ID]&redirect_uri=[YOUR_REDIRECT_URI]&scope=[ASSIGNED_SCOPES]&state=[RANDOM_VALUE]&code_challenge=[PKCE_CHALLENGE]&code_challenge_method=S256
URL parameters:
response_type=code: fixed value.client_id=[YOUR_CLIENT_ID]: your client identifier.redirect_uri=[YOUR_REDIRECT_URI]: must exactly match one of the URIs provided.scope=[ASSIGNED_SCOPES]: the list of permissions assigned to you, separated by spaces.state=[RANDOM_VALUE]: a random string that prevents CSRF attacks, to be checked on return.code_challenge=[PKCE_CHALLENGE]: (PKCE) the generated challenge.code_challenge_method=S256: (PKCE) indicates that the challenge was hashed with SHA-256.
After giving consent, the user is redirected to your redirect_uri with the code and state parameters.
Step 3: Exchange the authorization code for an access token
With the code received, make a POST call to the Yapla token endpoint to get the access_token.
- Endpoint:
POST https://login.yapla.com/oauth/token - Header:
Content-Type: application/x-www-form-urlencoded
Request body:
grant_type:authorization_codecode: the authorization code received.redirect_uri: the same redirect URI.client_id: yourClient ID.client_secret: (confidential client) yourClient Secret.code_verifier: (PKCE) thecode_verifieryou generated and kept.
Example with curl (PKCE flow):
curl -X POST \ https://login.yapla.com/oauth/token \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=authorization_code' \ -d 'code=[RECEIVED_CODE]' \ -d 'redirect_uri=[YOUR_REDIRECT_URI]' \ -d 'client_id=[YOUR_CLIENT_ID]' \ -d 'code_verifier=[YOUR_CODE_VERIFIER]'
Expected response (JSON):
{
"access_token": "xyz789...",
"token_type": "Bearer",
"expires_in": 86400,
"refresh_token": "abc123...",
"scope": "c3_12345 c3_67890"
}
The access token is valid for 24 hours. The expires_in value gives, in seconds, the time remaining at the moment of the response: it is about 86,400 and can be slightly lower. Rely on the value received to schedule the renewal.
Store the access_token and the refresh_token securely, on the server side. The refresh_token lets you get new tokens without any action from the user.
Step 4: Use the access token
Use the access_token to make authenticated calls to the Yapla GraphQL API.
API endpoint:
- North America:
https://s1.yapla.com/graphql - Europe:
https://s2.yapla.com/graphql
Example call:
curl -X POST \
https://[s1|s2].yapla.com/graphql \
-H 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
-H 'Content-Type: application/json' \
-d '{"query": "{ company { name } }"}'
Renew the access token
Before the access token expires, get a new pair of tokens with the refresh_token, without asking the user for consent again. The refresh_token is valid for 7 days.
- Endpoint:
POST https://login.yapla.com/oauth/token - Header:
Content-Type: application/x-www-form-urlencoded
Request body:
grant_type:refresh_tokenrefresh_token: the lastrefresh_tokenreceived.client_id: yourClient ID.client_secret: (confidential client) yourClient Secret. A public client (PKCE) does not send this parameter.scope: (optional) without this parameter, the initial permissions are kept. It can only request permissions already granted.
Example with curl (confidential client):
curl -X POST \ https://login.yapla.com/oauth/token \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=refresh_token' \ -d 'refresh_token=[YOUR_REFRESH_TOKEN]' \ -d 'client_id=[YOUR_CLIENT_ID]' \ -d 'client_secret=[YOUR_CLIENT_SECRET]'
The response has the same form as in step 3 and contains a new access_token (valid for 24 hours) and a new refresh_token (valid for 7 days from its issue).
Each successful renewal replaces the previous pair of tokens: the previous refresh_token can no longer be used. Save the new refresh_token at each renewal; otherwise, the next call fails and a new authorization from the user is required.
Renewal is only done on https://login.yapla.com/oauth/token. The /oauth2/token address of the Yapla single sign-on (SSO) does not support renewal with a refresh_token.
Keep a connection active without a new authorization
Token lifetimes (24 hours for the access token, 7 days for the refresh_token) are the same for all OAuth clients and cannot be set client by client. An integration can, however, stay connected for several years if each renewal succeeds before the deadline:
- Renew on the server side, before the deadline: trigger the renewal automatically, with enough margin before the access token expires and well before the 7 days of the
refresh_token. - Save the new
refresh_tokenafter each success: store it securely and replace the previous one. - Avoid simultaneous renewals: only one process should renew the tokens at a time, because the first renewal makes the previous
refresh_tokenunusable for the others. - Protect the
Client Secret: store it securely, just like the tokens.
A new authorization from the user (steps 2 and 3) is required in the following cases:
- the last
refresh_tokenhas expired, after more than 7 days without renewal; - the
refresh_tokenor the access has been revoked; - the OAuth client has been revoked.