How to calculate AWS signature V4 in Swagger before request

后端 未结 2 929
生来不讨喜
生来不讨喜 2020-12-31 19:41

For our AWS API Endpoints we use AWS_IAM authorization and want to make a call from Swagger UI. To make a successful call there must be 2 headers \'Authorization\' and \'x-

2条回答
  •  一生所求
    2020-12-31 20:12

    There is built-in support in swagger-js to add requestInterceptors to do just this. The swagger-ui project uses swagger-js under the hood.

    Simply create a request interceptor like such:

    requestInterceptor: {
      apply: function (request) {
        // modify the request object here
        return request;
      }
    }
    

    and apply it to your swagger instance on creation:

    window.swaggerUi = new SwaggerUi({
      url: url,
      dom_id: "swagger-ui-container",
      requestInterceptor: requestInterceptor,
    

    Here you can set headers in the request object (note, this is not the standard javascript http request object, inspect it for details). But you do have access to all headers here, so you can calculate and inject them as needed.

提交回复
热议问题