lepture / authlib

The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included.
https://authlib.org/
BSD 3-Clause "New" or "Revised" License
4.55k stars 452 forks source link

New token will not be fetched if grant_type='client_credentials' is passed for fetch_token() #660

Open bryan-prime opened 3 months ago

bryan-prime commented 3 months ago

Describe the bug

If I pass client_credentials as the grant_type it will not automatically fetch the new token.

To Reproduce

My code where I pass the grant_type.

self.oauth2client = OAuth2Session(token_endpoint=f"{base_url}/auth/token")
self.oauth2client.fetch_token(grant_type="client_credentials",)

https://github.com/lepture/authlib/blob/master/authlib/oauth2/client.py#L199-L204

self.metadata is only set if None was passed for grant_type

https://github.com/lepture/authlib/blob/master/authlib/oauth2/client.py#L279-L284

self.metadata['grant_type'] will be None so it will not fetch the new token.

My workaround was passing nothing for fetch token because it luckily defaults to client_credentials if nothing was passed for the grant_type.

Expected behavior

A clear and concise description of what you expected to happen.

Environment:

Additional context

Add any other context about the problem here.