-
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.
- Loading branch information
araya
authored and
araya
committed
Jul 13, 2023
1 parent
b335c41
commit c357b34
Showing
3 changed files
with
59 additions
and
17 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
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,41 @@ | ||
import requests | ||
|
||
# AWS Cognito configuration | ||
cognito_domain = 'g2cjr8hzv8.execute-api.us-east-1.amazonaws.com' | ||
client_id = '27m4fubn23111ud58hkouieqb9' | ||
username = 'internaluser@test.com' | ||
password = 'PB74y*MfPFNT' | ||
|
||
# Perform authentication | ||
session = requests.Session() | ||
|
||
# Step 1: Initiate authentication by requesting the login page | ||
login_url = f'https://{cognito_domain}/login' | ||
response = session.get(login_url) | ||
|
||
# Step 2: Extract the required form parameters from the login response | ||
csrf_token = response.cookies['XSRF-TOKEN'] | ||
form_action = response.text.split('form action="')[1].split('"')[0] | ||
|
||
# Step 3: Construct the login request payload | ||
login_payload = { | ||
'username': username, | ||
'password': password, | ||
'csrfToken': csrf_token | ||
} | ||
|
||
# Step 4: Submit the login request | ||
login_request_url = f'https://{cognito_domain}{form_action}' | ||
response = session.post(login_request_url, data=login_payload, allow_redirects=False) | ||
|
||
# Step 5: Extract the Cognito ID token from the response | ||
id_token = response.cookies['cognito-id-token'] | ||
|
||
# Print the Cognito ID token (you can store it for subsequent requests) | ||
print("Cognito ID token:", id_token) | ||
|
||
# Now you can use the session object to make authenticated requests to URLs behind AWS Cognito | ||
# For example: | ||
protected_url = 'https://mdctmcrval.cms.gov/' | ||
response = session.get(protected_url) | ||
print(response.text) |
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,15 +1,14 @@ | ||
[{ | ||
"contextName": "MyContext", | ||
"includeRegexes": ["^https?://mdctmcrval.cms.gov/"], | ||
"excludeRegexes": [], | ||
"authentication": { | ||
"method": "formBasedAuthentication", | ||
"loginUrl": "https://cognito-idp.us-east-1.amazonaws.com", | ||
"loginRequestData": "username=internaluser@test.com&password=PB74y*MfPFNT", | ||
"loginRequestType": "POST", | ||
"loginRequestHeaders": { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
"loginRequestCookies": [] | ||
} | ||
}] | ||
[ | ||
{ | ||
"contextName": "MyContext", | ||
"includeRegexes": ["^https?://mdctmcrval.cms.gov/"], | ||
"excludeRegexes": [], | ||
"authentication": { | ||
"method": "scriptBasedAuthentication", | ||
"script": { | ||
"type": "python", | ||
"file": "authentication.py" | ||
} | ||
} | ||
} | ||
] |