-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserinfo.py
More file actions
40 lines (36 loc) · 1.29 KB
/
Copy pathuserinfo.py
File metadata and controls
40 lines (36 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
####################################################
# Retrive USER-INFORMATION #
####################################################
from dotenv import load_dotenv
import requests
import os
# The URL to retrieve user information
def retrive_user_information(access_token):
load_dotenv()
domain= os.getenv('HOSTED_UI_COGNITO_DOMAIN')
region= os.getenv('REGION')
url = f"https://{domain}.auth.{region}.amazoncognito.com/oauth2/userInfo"
# Headers for the request
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/x-amz-json-1.1",
"User-Agent": "ChatAdex/1.0",
"Accept": "*/*",
"Host": f"{domain}.auth.{region}.amazoncognito.com",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive"
}
# signing-chatadex/read.
# Send the GET request
response = requests.get(url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
user_info = response.json()
return {
"username": user_info['username'],
"email": user_info['email']
}
else:
# Print the error
return {"error":f"Failed to fetch user information. Status Code: {response.status_code}, Response: {response.text}"}