Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
This package provides utilities to add AWS Signature V4 authentication infrormation to calls made by python httpx library.
This package provides utilities to add AWS Signature V4 authentication infrormation to calls made by python httpx library.
pip install httpx-auth-awssigv4
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
)
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"
)
FAQs
This package provides utilities to add AWS Signature V4 authentication infrormation to calls made by python httpx library.
We found that httpx-auth-awssigv4 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.