swagger-ui: redirect endpoint returning a 302 redirect to AWS S3 - generating an auth problem
I have a download endpoint in my API which is redirecting the user to a AWS S3 presigned URL
Here is the swagger file describing my endpoint:
openapi: 3.0.0
info:
  title: My API
  description: API
  version: 2.0
servers:
  - url: myapi.com
    description: API v2.0.
components:
  securitySchemes:
    Auth:
      type: apiKey
      in: header
      name: Authorization
security:
  - Auth: []
paths:
  /download/:
    get:
      summary: Download
      description: Download
      responses:
        '302':
          description: Redirects to a location for downloading
          content:
            application/gzip:
              schema:
                type: string
                format: binary
My problem is when the SwaggerUI (version 3.14.2) it trying the endpoint it does get the redirect order, but when it tries to go the redirect location it for some reason sends the “Authorization” header to that URL although it’s not on the same domain.
This problem is causing AWS S3 to omit the following error because it’s receiving both “Authorization” header and the “AWSAccessKeyId” get parameters.
<?xml version="1.0"?>
<Error>
  <Code>InvalidArgument</Code>
  <Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified</Message>
  <ArgumentName>Authorization</ArgumentName>
  <ArgumentValue>Token TTTTTTTTTTTTT</ArgumentValue>
  <RequestId>RRRRRRRRRRRRRR</RequestId>
  <HostId>HHHHHHHHHHHHHHHH</HostId>
</Error>
Any idea how to solve this issue?
About this issue
- Original URL
 - State: open
 - Created 6 years ago
 - Comments: 20 (2 by maintainers)
 
@kobymeir @MaxHo1234, upon further inspection, this is a limitation within the browser. The request is being transparently followed, with no way to control the behavior from within a web application like Swagger UI. Postman gets around this with their Interceptor extension, which is not subject to the same constraints.
I’m going to keep this open: if there’s sufficient interest, we could consider building a similar extension that allows users to circumvent browser limitations.
Hi @shockey
There is no reason to pass on the authorization headers as you have no idea where the redirect it going, thus potentially exposing the authorization token to a 3rd party that we might not want them to receive the token.
Hope that my answered helped 😃
Hey shockey, we have the same problem here. Currently you cannot use Swagger-Ui with AWS, if you have such an authorization step.
Swagger-Ui sends the original authorization token together with the redirect authorization token to AWS. AWS complains with a 400 bad request. Swagger-Ui should send only the redirect authorization token in the final request, then it would work.
Currently, we are forced to use Postman instead of Swagger-Ui, because of this problem. It would be nice, if this gets fixed soon.
I too came across this problem and realized that when
fetchredirects to the presigned S3 URL you can’t prevent it from sending the Authorization headers from your API.Eventually I have able to get this working by using the
responseInterceptorconfiguration argument for Swagger with a custom function that detects the bad request (400) response from S3 and then re-issues thefetchrequest withcredentials: 'omit'.Here is my custom response interceptor for Swagger:
Then I had to specify my custom
myResponseInterceptorwhen initializing the Swagger UI inindex.htmlI was using ASP.NET Core and used these instructions to provide my own
index.htmlfor Swagger UI: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#customize-indexhtmlAfter all that, this surprisingly worked and I was able to see the redirected response from S3 in Swagger.