authlib / authlib/demo-oauth-client
Multiple OAuth clients registered
- Dominant language
- Python
- Stars
- 287
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
When there are more than 1 oauth client to connect, the application always picks the last one in the definition instead of any of the defined ones. There should be a way to keep every client registered and usable in subsequent calls. This is the example:
```auth.py
# 1. Register client_1
oauth.register(
"client_1",
client_id = client_id,
client_secret = client_secret,
client_kwargs = {
"scope": "openid profile email",
},
server_metadata_url = f'{domain}/.well-known/openid-configuration'
)
# 2. Register client_2
oauth.register(
"client_2",
client_id = client_id_2,
client_secret = client_secret_2,
client_kwargs = {
"scope": "openid profile email",
},
server_metadata_url = f'{domain_2}/.well-known/openid-configuration'
)
@app.route('client_1/login')
def client_1_login():
return oauth.client_1.....
@app.route('client_2/login')
def client_2_login():
return oauth.client_2....
```
when someone accesses route client_1/login, an error will raise with the following traceback:
```
Traceback (most recent call last):
File "/usr/src/app/.local/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/usr/src/app/.local/lib/python3.9/site-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/src/app/.local/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/src/app/.local/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/src/app/.local/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/src/app/app/views/auth.py", line xxx, in client_1_login
token = oauth.client_1.authorize_access_token()
File "/usr/src/app/.local/lib/python3.9/site-packages/authlib/integrations/base_client/registry.py", line 118, in __getattr__
raise AttributeError('No such client: %s' % key)
AttributeError: No such client: client_1
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the two registrations from auth.py and trace the failing client lookup through app/views/auth.py and the registry.py code shown in the traceback. Verify that both client_1 and client_2 remain accessible for their respective routes, and add or run coverage for each authorization flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100