🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

aws4-react

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws4-react

AWS4 React Library is used to get AWS Signature.

0.2.3
latest
Source
npm
Version published
Weekly downloads
11
-21.43%
Maintainers
1
Weekly downloads
 
Created
Source

AWS4 React

AWS4 React Library is used to get AWS Signature.

This library is to create a signed AWS API request in react or any js project.

Installation

Use the package manager npm to install aws4-react.

npm i aws4-react

or
yarn add aws4-react

Usage

import { AWSSigner } from 'aws4-react';

 let params = {
    data: JSON.stringify(body),
    method: 'GET',
    url:
      'https://z7hgc1k4qb.execute-api.us-east-1.amazonaws.com/master/batches',
  };
  let cred = {
    secret_key: 'kdjaskdjaksd',
    access_key: 'dkasndkjasjdkas',
    session_token: '',
  };

  console.log(cred);

  const serviceInfo = {
    region: 'us-east-1',
    service: 'execute-api',
  };

  const headers = AWSSigner.sign(params, cred, serviceInfo);

/* It returns
  {
  data?: string;
  metho?: string;
  url?: string;
  headers?: {
    host?: string;
    'x-amz-date': string;
    Authorization: string;
  };
}
 */

Now you can send the Authorization in the header as follows

Example with RTK Query

const signedHeaders = AWSSigner.sign(params, cred, serviceInfo);
fetchBaseQuery({
    baseUrl: "example.com",
    prepareHeaders: (headers) => {
       const authHeader = signedHeaders.headers
        for (let key in authHeader) {
         headers.set(key, authHeader[key]);
      }
      return headers;
    },
  });

Example with Axios

const signedHeaders = AWSSigner.sign(params, cred, serviceInfo);
  const authHeader = signedHeaders.headers
  axios.post('url', {"body":data}, {
    headers: {
    'Authorization': authHeader.Authorization
    }
  }
)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Keywords

react

FAQs

Package last updated on 30 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts