This document explains how web server applications use Olist OAuth 2.0 endpoints to implement OAuth 2.0 authorization to access Olist APIs. You will need to follow the steps below in order to authenticate and use our API:
WIth the ID token you will be able to make request to our API.
After obtaining your sandbox credentials, the first step is to open the Olist's authorization screen. In that screen, the seller will inform his email and password and allow your application. You will need to form a GET HTTPS request with the following parameters.
Your URL will look like the example below:
https://auth-engine.olist.com/realms/3rd-party-sandbox/protocol/openid-connect/auth?client_id=fake_client_id&email=fake_client_id@partners-sandbox-api.olist.com&response_type=code&redirect_uri=http://localhost:8001/event&scope=openid%20email%20profile&state=TOPSECRET123
Users are required to give consent if your app requests any new information about them, or if your app requests account access that they have not previously approved.
You should retrieve the base URI from https://id.olist.com/openid/.well-known/openid-configuration/ using the key authorization_endpoint.
The response is sent to the redirect_uri that you specified in the request. All responses are returned in the query string, as shown below:
http://localhost:8001/event?code=b0eae53a501449dfbf560d5603aafefc&state=TOPSECRET123
On the server, you must confirm that the state received from Olist matches the session token you created in the previous step. This round-trip verification helps to ensure that the user, not a malicious script, is making the request.
The response includes a code parameter, an one-time authorization code that your server can exchange for an access token and ID token. Your server can make this exchange by sending an HTTPS POST request with the following parameters:
authorization_code
.curl --location 'https://auth-engine.olist.com/realms/3rd-party-sandbox/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization;' \
--data-urlencode 'code=0ec4918c-d2a9-4551-a0ad-9e1a686c8b08.73c28705-9985-45d4-aeb6-e80f92aa44bf.ea01e8b5-e913-45dc-84e3-14e16786a1c2' \
--data-urlencode 'client_id=fake_client_id' \
--data-urlencode 'client_secret=ne3FW89fj349N3IoJHtUSbuyk8N9nRZB' \
--data-urlencode 'redirect_uri=http://localhost:8001/event' \
--data-urlencode 'grant_type=authorization_code'
A successful response to this request contains the following fields in a JSON array:
You should retrieve the base URI from https://id.olist.com/openid/.well-known/openid-configuration/ using the key token_endpoint.
After obtaining user information from the ID token, you should query your app's user database. Make a GET HTTP request to the partners app. If the user already exists in your database, you should start an application session for that user.
curl --location 'https://partners-sandbox-api.olist.com/v1/sellers/' \
--header 'Accept: application/json' \
--header 'Authorization: JWT {id_token}'
And this is the response example:
{
"count":1,
"next":null,
"previous":null,
"results":[
{
"cnpj":"12345678912345",
"company_name":"",
"cpf":"",
"email":"test@olist.com",
"id":"23da1das-fee1-40ea-9ed2-asdsa65146sd",
"mobile_phone":"",
"name":"Olist Teste",
"phone":""
}
]
}
Access tokens periodically expire. You can refresh an access token without prompting the user for permission (including when the user is not present).
To refresh an access token, your application sends an HTTPS POST request to Olist's authorization server that includes the following parameters:
curl --location 'https://auth-engine.olist.com/realms/3rd-party-sandbox/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: JWT eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJZel90TVpiXzdOd2NMZVVaT0tYc2NRdW8wUE4zN0JvYkNONjhFdE80WVFzIn0.eyJleHAiOjE3MzY2MjU3MzUsImlhdCI6MTczNjUzOTMzNSwiYXV0aF90aW1lIjoxNzM2NTM5MjkxLCJqdGkiOiI0NjYwZDQxZS1kOTRiLTRlZmItOTMzZS1iM2U3OWVmNGMwYjciLCJpc3MiOiJodHRwczovL2F1dGgtZW5naW5lLm9saXN0LmNvbS9yZWFsbXMvM3JkLXBhcnR5LXNhbmRib3giLCJhdWQiOiJkZXZlbG9wZXJzIiwic3ViIjoiMDYzYTlkYzctZGU5MC00N2NmLWFiZGUtMWRhMTc0MTMwY2RhIiwidHlwIjoiSUQiLCJhenAiOiJkZXZlbG9wZXJzIiwic2Vzc2lvbl9zdGF0ZSI6IjllNTViNTJjLTQyYTItNGM0My05NmEyLWFkOWFlMDk1Zjg0MSIsImF0X2hhc2giOiJjc2NLQnFvUjFOaXJhSlM0UWcyaEpRIiwiYWNyIjoiMSIsInNpZCI6IjllNTViNTJjLTQyYTItNGM0My05NmEyLWFkOWFlMDk1Zjg0MSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLC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NDJhMi00YzQzLTk2YTItYWQ5YWUwOTVmODQxIiwic2NvcGUiOiJvcGVuaWQgZW1haWwgcHJvZmlsZSIsInNpZCI6IjllNTViNTJjLTQyYTItNGM0My05NmEyLWFkOWFlMDk1Zjg0MSJ9.yvi5KW3Nh9gki0n9_XMriH4vxxhEa0fw31lvKn5Gpag' \
--data-urlencode 'grant_type=refresh_token'
And this is the response example:
{
"access_token": "4ffad88b774b42ec8026e9fc..",
"refresh_token": "0f0111f2e7c64a00ad43492f2...",
"token_type": "bearer",
"expires_in": 86400,
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6..."
}