Hi everyone, happy new year !
I am building a custom app for Sinao and I am struggling with the connection part.
Their authentication process is as follow:
- Make a POST /login request with Email and Password as query parameters to obtain a Token
- Make a GET request /refresh to refresh token
This process is similar to Oauth 2.0 authentication process except that there is no “pre-authorize” nor “authorize” steps.
I therefore tried to build a Connection by selecting Type = Other where I put the following code in the Communication tab:
{
"token": {
"url": "https://api.sinao.app/v1/login",
"method": "POST",
"body": {
"email": "{{parameters.email}}",
"password": "{{parameters.password}}"
},
"type": "urlencoded",
"response": {
"data": {
"expires": "{{addSeconds(now, body.expires_in)}}",
"accessToken": "{{body.access_token}}"
},
"expires": "{{addDays(now, 14)}}"
},
"log": {
"sanitize": ["request.body.email", "request.body.password", "response.body.accessToken"]
}
},
"refresh": {
"condition": "{{data.expires < addMinutes(now, 5)}}",
"url": "https://api.sinao.app/v1/refresh",
"method": "GET",
"headers": {
"Authorization": "Bearer {{data.accessToken}}"
},
"type": "urlencoded",
"response": {
"data": {
"expires": "{{addSeconds(now, body.expires_in)}}",
"accessToken": "{{body.access_token}}"
},
"expires": "{{addDays(now, 14)}}"
},
"log": {
"sanitize": ["request.headers.Authorization", "response.body.accessToken"]
}
},
"info": {
"url": "https://api.sinao.app/v1/me",
"headers": {
"Authorization": "Bearer {{connection.accessToken}}"
},
"response": {
"uid": "{{body.id}}",
"metadata": {
"type": "text",
"value": "{{body.firstname}} {{body.lastname}}"
},
"error": {
"message": "[{{statusCode}}] {{if(body.message, body.message, body)}}"
}
},
"log": {
"sanitize": [
"request.headers.Authorization"
]
}
}
}
However, I keep getting 401 error when testing the connection with a simple module Get current user. Would anyone know where the problem comes from ?
Thanks.