openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[typescript-axios] Add support for AWSv4 Signature

Open varqasim opened this issue 1 year ago • 5 comments

Add AWS v4 signature support to typescript-axios client generator by making use of https://github.com/jamesmbourne/aws4-axios. Addresses request #7034.

Example

OpenAPI Definition

components:
    sigv4:
      type: apiKey
      name: Authorization
      in: header
      x-amazon-apigateway-authtype: awsSigv4
paths:
  /v1/user:
    post:
      operationId: createUser
      summary: Create a single user
      security:
        - sigv4: []
      ....

SDK Usage

import * as UserServiceSDK from 'sdk';

class ApiConfig extends UserServiceSDK.Configuration { }
const api = new UserServiceSDK.DefaultApi(new ApiConfig({
  basePath: process.env.SERVICE_A_BASE_URL,
  awsv4: {
    options: {
      region: process.env.AWS_REGION,
      service: 'execute-api'
    },
    credentials: {
      accessKeyId: process.env.AWS_ACCESS_KEY_ID,
      secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
      sessionToken: process.env.AWS_SESSION_TOKEN
    }
  }
}));

PR checklist

  • [x] Read the contribution guidelines.
  • [x] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • [x] Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH) Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • [x] File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • [x] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

varqasim avatar Mar 23 '24 21:03 varqasim

@davidgamero @amakhrov Your reviews would be appreciated

varqasim avatar Mar 23 '24 21:03 varqasim

any chance to continue ?

maratsh avatar Aug 28 '24 17:08 maratsh

@maratsh For now I opted in taking this branch which introduces aws4 and build it locally as a docker image and make use of it to achieve my goal. There are plans to continue this, but I am not sure if the direction I am taking this change is flexible enough for other use cases out there that want to achieve something similar.

varqasim avatar Feb 09 '25 07:02 varqasim

Hey @varqasim !! Thanks so much for this contribution. I was scoping out what it would take to implement this myself in typescript-axios and several other generators. I have not contributed to this repo before, so am working on learning how it all comes together. I am happy to help test with our use case as a consumer and collab on how to make this come together.

NiltiakSivad avatar May 05 '25 12:05 NiltiakSivad

Hey @varqasim !! Thanks so much for this contribution. I was scoping out what it would take to implement this myself in typescript-axios and several other generators. I have not contributed to this repo before, so am working on learning how it all comes together. I am happy to help test with our use case as a consumer and collab on how to make this come together.

Hello @NiltiakSivad, I am glad you found this useful. Please go ahead and test it out if you need to or even take over the PR if you'd like. I am not sure how to take this further in order to get it approved as the discussion came to a halt, but what I did is built my own Docker image out of this PR and using it internally and works fine for us for the time being.

varqasim avatar May 05 '25 18:05 varqasim

thanks for the pr

closed via https://github.com/OpenAPITools/openapi-generator/pull/22174 with resolved merge conflicts

wing328 avatar Oct 18 '25 08:10 wing328