最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Authlib Oauth2 Azure ssl error "The request body must contain the following parameter: 'client_id&

programmeradmin1浏览0评论

I am trying to use Authlib 1.5.1 to authenticate against backend, using Azure as an authentication provider. My configuration is simple, I'm trying to follow docs:

oauth.register(
  'azure',
  server_metadata_url=app.config['AZURE_METADATA_URL'],
  client_id=app.config['AZURE_CLIENT_ID'],
  client_secret=app.config['AZURE_CLIENT_SECRET'],
  client_kwargs={
    'scope': 'api://XXXXX0-YYYYY-ZZZZZZZZZZZZZ/api.access',
  }
)

Flask app config file is simple as well:

import os
from config_reader import config

TENANT_ID = 'XXXXX0-YYYYY-ZZZZZZZZZZZZZ'
AZURE_CLIENT_ID = os.getenv("AZ_CLIENT_ID")
AZURE_CLIENT_SECRET = os.getenv("AZ_CLIENT_SECRET")
AZURE_AUTHORITY = f'/{TENANT_ID}'
AZURE_REDIRECT_URI = config['callback_url']
AZURE_ACCESS_TOKEN_URL = f'/{TENANT_ID}/oauth2/v2.0/token'
AZURE_AUTHORIZE_URL = f'/{TENANT_ID}/oauth2/v2.0/authorize'
AZURE_API_BASE_URL = config['api']['url']
AZURE_METADATA_URL = f'/{TENANT_ID}/v2.0/.well-known/openid-configuration'

Traceback:

File "C:\projects\myprojectpath\venv\Lib\site-packages\flask\app.py", line 1536, in __call__
return self.wsgi_app(environ, start_response)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\flask\app.py", line 1514, in wsgi_app
response = self.handle_exception(e)
           ^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\flask\app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\flask\app.py", line 919, in full_dispatch_request
rv = self.handle_user_exception(e)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\flask\app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
     ^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\flask\app.py", line 902, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\scomat-frontend\ui.py", line 52, in authorize
token = oauth.azure.authorize_access_token()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\authlib\integrations\flask_client\apps.py", line 107, in authorize_access_token
token = self.fetch_access_token(**params, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\authlib\integrations\base_client\sync_app.py", line 376, in fetch_access_token
token = client.fetch_token(token_endpoint, **params)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\authlib\oauth2\client.py", line 245, in fetch_token
return self._fetch_token(
       

File "C:\projects\myprojectpath\venv\Lib\site-packages\authlib\oauth2\client.py", line 444, in _fetch_token
return self.parse_response_token(resp)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\projects\myprojectpath\venv\Lib\site-packages\authlib\oauth2\client.py", line 419, in parse_response_token
raise self.oauth_error_class(
^

authlib.integrations.base_client.errors.OAuthError: invalid_request: AADSTS900144: The request body must contain the following parameter: 'client_id'. Trace ID: XXXXXXXXX Correlation ID: XXXXXXXX Timestamp: 2025-03-13 14:43:59Z

Variables seems to be propagated properly, but on oauth.azure.authorize_access_token() I am getting error

authlib.integrations.base_client.errors.OAuthError: invalid_request: AADSTS900144: The request body must contain the following parameter: 'client_id'.

What am I missing?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论