OAuth Authentication
Tiendy uses Oauth to provide authorized access to its API.
1.- Initiating authentication
To initiate authentication, redirect the store owner to the following URL:
GET https://STORE_NAME.mitiendy.com/admin/auth/authorize
with the following parameters:
- client_id: The API key for your app
- scope: The list of required scopes (permissions) for your app.
- redirect_uri (optional): The URL to redirect the user after confirmation. This URL must start with the URL specified in your application settings.
A confirmation form to grant the requested permissions will be shown to the store owner
Once the store owner has granted access to your application they are redirected to the URL specified in the redirect_uri parameter with a temporary authorization code as a GET parameter. Given the redirect URL:
http://mytiendyapp.com/app
The call will look like this:
http://mytiendyapp.com/app?code=TEMPORARY_AUTH_CODE
2.- Obtaining the access token
Para obtener el token permanente es necesario realizar una llamada a la siguiente URL:
POST https://STORE_NAME.mitiendy.com/admin/auth/token
Con los siguientes parámetros:
- client_id: La clave API de su app
- client_secret: La clave compartida de la app
- code: El código de autorización obtenido en el paso anterior
Ejemplo de llamada:
curl https://STORE_NAME.mitiendy.com/admin/auth/token -d 'code=e200642a3e99fd38735bbf5ee9e062e750117b6e&client_id=testcid&client_secret=testsecret'
La respuesta será un objeto JSON con el código del token. Un ejemplo de respuesta sería:
{
"access_token":"fb14a61f52b8cf63f9828c7d8f74d041948c6372",
"expires_in":31536000,
"scope":"read_products"
}
3.- Accediendo a los recursos
Una vez obtenido el token permanente, puede usarlo para acceder a los recursos de la API. Para ello debe establecer la cabecera X-Tiendy-Access-Token en cada llamada a la API conteniendo el token.
X-Tiendy-Access-Token: fb14a61f52b8cf63f9828c7d8f74d041948c6372
También es posible usar el token como parámetro de la URL (access_token) pero recomendamos el uso de la cabecera X-Tiendy-Access-Token.
Ejemplo:
curl -H "X-Tiendy-Access-Token: 237c445ea655b2f380eac1974a9f36feb1053317" https://STORE_NAME.mitiendy.com/admin/products.json
4.- Permisos
Según las necesidades de cada aplicación es posible obtener permisos para acceder a determinados recursos de la tienda.
(read|write)_products
(read|write)_orders
Ejemplo:
curl https://STORE_NAME.mitiendy.com/admin/auth/authorize?client_id=API_KEY&scope=write_products%20read_orders
Los permisos de escritura llevan implícitos los de lectura por lo que no es necesario pedir ambos.
