forked from caffeinehit/django-oauth2-provider
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from stormsherpa/aws_auth
Add aws_identity grant_type for getting access tokens
- Loading branch information
Showing
26 changed files
with
623 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Read the Docs configuration file for Sphinx projects | ||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details | ||
|
||
# Required | ||
version: 2 | ||
|
||
# Set the OS, Python version and other tools you might need | ||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.12" | ||
# You can also specify other tool versions: | ||
# nodejs: "20" | ||
# rust: "1.70" | ||
# golang: "1.20" | ||
|
||
# Build documentation in the "docs/" directory with Sphinx | ||
sphinx: | ||
configuration: docs/conf.py | ||
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs | ||
# builder: "dirhtml" | ||
# Fail on all warnings to avoid broken references | ||
# fail_on_warning: true | ||
|
||
# Optionally build your docs in additional formats such as PDF and ePub | ||
# formats: | ||
# - epub | ||
|
||
# Optional but recommended, declare the Python requirements required | ||
# to build your documentation | ||
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html | ||
# python: | ||
# install: | ||
# - requirements: docs/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ARG PYVERSION=3.9.19-bullseye | ||
|
||
FROM python:${PYVERSION} AS dev | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt /app/ | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -q -y \ | ||
jq \ | ||
&& apt-get clean | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
FROM dev as prod | ||
|
||
COPY ./ /app/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import os | ||
import sys | ||
import json | ||
|
||
from datetime import datetime | ||
from urllib import request, error | ||
import requests | ||
|
||
import boto3 | ||
# aws-v4-signature==2.0 | ||
from awsv4sign import generate_http11_header | ||
|
||
service = 'sts' | ||
region = 'us-west-2' | ||
|
||
session = boto3.Session() | ||
creds = session.get_credentials() | ||
access_key = creds.access_key | ||
secret_key = creds.secret_key | ||
session_token = creds.token | ||
|
||
print(f"access_key: {access_key[:10]}<redacted...>") | ||
print(f"secret_key: {secret_key[:10]}<redacted...>") | ||
print(f"session_token: {session_token[:20]}<redacted...>") | ||
print(f"profile: {os.environ.get('AWS_PROFILE')}") | ||
|
||
url = 'https://sts.{region}.amazonaws.com/'.format(region=region) | ||
httpMethod = 'post' | ||
canonicalHeaders = { | ||
'host': f'sts.{region}.amazonaws.com', | ||
'x-amz-date': datetime.utcnow().strftime('%Y%m%dT%H%M%SZ'), | ||
'content-type': 'application/x-www-form-urlencoded; charset=utf-8', | ||
} | ||
if session_token: | ||
canonicalHeaders['x-amz-security-token'] = session_token | ||
|
||
payload_str = "Action=GetCallerIdentity&Version=2011-06-15" | ||
|
||
headers = generate_http11_header( | ||
service, region, access_key, secret_key, | ||
url, 'post', canonicalHeaders, {}, | ||
'', payload_str | ||
) | ||
|
||
token_request_args = { | ||
"grant_type": "aws_identity", | ||
"region": region, | ||
"post_body": payload_str, | ||
"headers_json": json.dumps(headers), | ||
} | ||
print(payload_str) | ||
print(json.dumps(headers, indent=4)) | ||
|
||
req = request.Request("https://sts.us-west-2.amazonaws.com/", data=payload_str.encode('utf-8'), headers=headers, method='POST') | ||
try: | ||
response = request.urlopen(req) | ||
print(f"Local request test result: {response.read()}") | ||
except error.HTTPError as e: | ||
print(f"HTTPError: {e}: {e.fp.read()}") | ||
sys.exit(1) | ||
|
||
print("Attempting access_token grant request with same signed request:\n") | ||
|
||
token_response = requests.post("http://localhost:8000/oauth2/access_token", | ||
data=token_request_args) | ||
token_info = token_response.json() | ||
|
||
print(token_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
services: | ||
test: | ||
build: | ||
context: . | ||
target: dev | ||
user: ${UID} | ||
volumes: | ||
- ${WORKSPACE:-.}:/app | ||
environment: | ||
- DJANGO_SETTINGS_MODULE=tests.settings | ||
|
||
web: | ||
build: | ||
context: . | ||
target: dev | ||
user: ${UID} | ||
volumes: | ||
- ${WORKSPACE:-.}:/app | ||
ports: | ||
- "8000:8000" | ||
environment: | ||
- DJANGO_SETTINGS_MODULE=tests.settings | ||
# entrypoint: [ "python3", "manage.py", "runserver" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = "4.0" | ||
__version__ = "4.2" | ||
# The major version is expected to follow the current django major version:q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.