Coder Social home page Coder Social logo

mmuppidi / httpx-auth-awssigv4 Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 2.0 396 KB

Amazon Web Services version 4 authentication for the Python httpx library

License: MIT License

Python 95.89% Makefile 4.11%
aws httpx aws-api-gateway aws-signature-v4 aws-sigv4 sigv4

httpx-auth-awssigv4's Introduction

httpx-auth-awssigv4

pypi python Build Status codecov

This package provides utilities to add AWS Signature V4 authentication infrormation to calls made by python httpx library.

Installation

pip install httpx-auth-awssigv4

Usage

Basic Usage

This library has primarily been developed to help add authentication support to httpx library while making calls to REST API deployed using AWS API Gateway service. Will be extended in future to help with calling AWS services.

import httpx
from httpx_auth_awssigv4 import Sigv4Auth

# creating a callable for httpx library
auth = Sigv4Auth(
    access_key="AWS_ACCESS_KEY_ID",
    secret_key="AWS_SECRET_ACCESS_KEY",
    service="execute-api",
    region="us-east-1"
)

# Calling an API endpoint deployed using AWS API Gateway which has
# AWS_IAM set as authorization type

response = httpx.get(
    url="https://<API ID>.execute-api.<Region>.amazonaws.com/prod/detials",
    params={"username": "tstark"},
    auth=auth
)

# Making a post call

response = httpx.get(
    url="https://<API ID>.execute-api.<Region>.amazonaws.com/prod/details",
    params={"username": "tstark"},
    json={"mission": "avengers"},
    auth=auth
)

With STS credentials

Sigv4Auth can be used with temporary credentials generated with tools like aws-sso-util.

import boto3
from httpx_auth_awssigv4 import Sigv4Auth

# fetch temporary credentials from AWS STS service
credentials = boto3.Session(profile_name="<profile>").get_credentials()

# creating a callable for httpx library
auth = Sigv4Auth(
    access_key=credentials.access_key,
    secret_key=credentials.secret_key,
    token=credentials.token
    service="execute-api",
    region="us-east-1"
)

Sigv4Auth can also be used with temporary credentials from AWS STS.

import boto3
from httpx_auth_awssigv4 import Sigv4Auth

# role with `execute-api` permissions
ROLE_ARN="arn:aws:iam::<ACCOUNT ID>:role/<ROLE NAME"

# fetch temporary credentials from AWS STS service
credentials = boto3.client('sts').assume_role(
    RoleArn=ROLE_ARN,
    RoleSessionName="httpxcall"
)["Credentials"]

# creating a callable for httpx library
auth = Sigv4Auth(
    access_key=credentials["AccessKeyId"],
    secret_key=credentials["SecretAccessKey"],
    token=credentials["SessionToken"]
    service="execute-api",
    region="us-east-1"
)

ToDo

  • Add examples on usage along with API backend deployment instructions.
  • Test the library with AWS services and add integration tests.

Credits

httpx-auth-awssigv4's People

Contributors

mmuppidi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

dmarchewka

httpx-auth-awssigv4's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.