DataConnectors icon indicating copy to clipboard operation
DataConnectors copied to clipboard

Swagger - Automatic token refresh on 401 is not triggered

Open StijnKing opened this issue 2 years ago • 6 comments

I am currently building a custom connector using a swagger file and an OAuth flow. The OAuth flow is working fine. It asks me to login and when successful, returns a usable access token. I can than use this token in web requests using Web.Contents method to make a call to our API. When the access token expires, the API call will result in a 401. This will trigger refreshing the access token using the stored refresh token and then it can successfully execute the API call again. This all works fine using Web.Contents and does not require any extra code.

However I want to achieve the same but with using the a swagger file. I import this file using OpenApi.Document. I can then use that to execute an API call. I have set Headers = [ Authorization = "Bearer " & access_token] in the config for loding the swagger file. This works fine until the access token expires. I receive this error:

image

This error states (if I understand it correctly) that the response is in the format of application/octet-stream. However I used Fiddler to catch this requests and there it gives this as response:

HTTP/1.1 401 Unauthorized
Server: Cowboy
Date: Tue, 28 Dec 2021 12:26:32 GMT
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: no-referrer-when-downgrade
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache
X-Request-Id: 60ab1996-0c22-43f9-bad8-83bc95c828ba
X-Runtime: 0.018296
Strict-Transport-Security: max-age=63072000; includeSubDomains
Vary: Origin
Transfer-Encoding: chunked
Via: 1.1 vegur

51
{"errors":{},"code":401,"message":"You are not authorized to access this record"}
0

This is obliviously just application/json, If I catch the request using Web.Contents I get the exact same response as above. Somehow the error I'm getting prevents it from refreshing the access token.

How can I solve this?

StijnKing avatar Dec 28 '21 12:12 StijnKing