在AWS Cognito中,令牌检查路径是通过AWS管理控制台的用户池设置中的“域名”选项来确定。
以下是一个使用AWS Cognito令牌检查路径的代码示例:
import requests
def check_token(token):
cognito_domain = 'https://your-cognito-domain.auth.us-east-1.amazoncognito.com'
token_check_endpoint = '/oauth2/userInfo'
headers = {'Authorization': token}
response = requests.get(cognito_domain + token_check_endpoint, headers=headers)
if response.status_code == 200:
# 令牌有效
return True
else:
# 令牌无效
return False
# 使用示例
access_token = 'your-access-token'
if check_token(access_token):
print("令牌有效")
else:
print("令牌无效")
在上面的示例中,我们使用/oauth2/userInfo作为令牌检查路径,使用requests库发送了一个GET请求,将访问令牌作为Authorization头部发送。
根据返回的响应状态码,我们可以确定令牌的有效性。如果状态码为200,则说明令牌有效;否则,令牌无效。
请确保将your-cognito-domain替换为你的Cognito用户池域名,并将your-access-token替换为要检查的访问令牌。