我使用存储令牌的外部 OAuth 服务器对 Flask API 上的用户进行身份验证,然后通过要求外部服务器内省我的 API 来内省令牌。我现在想测试我的功能,但不想在测试中使用外部服务器。因此我想在本地托管一个 OAuth 服务器进行测试。我在这个服务器上唯一想做的就是内省。是否可以以某种方式托管带有一些设置令牌、client_id、client_secret 的 OAuth 服务器,以便我可以完成此示例代码:
import requests
url = "http://localhost:8080/introspect"
payload = {
"token": "tokentokentoken",
'token_type_hint': 'access_token'
}
# Make a POST request to the specified URL with the payload
response = requests.post(url, data=payload, auth=("myClientID", "secret"))
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Print the token received in the response
print("Token:", response.json().get("token"))
else:
# Print an error message if the request was not successful
print("Error:", response.status_code, response.text)
我已经尝试过这个docker镜像https://github.com/navikt/mock-oauth2-server但我似乎不知道如何拥有预设令牌、client_id和client_secret。