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.52k stars 452 forks source link

JWT authentication issue #630

Open jmrbcu opened 7 months ago

jmrbcu commented 7 months ago

I need to authenticate with Ring Central JWT workflow. How to use Authlib for this case? I am unable to find how to do something like this in the documentation:

Request: POST

Headers: Content-type: application/x-www-form-urlencoded Authorization: Basic + base64_encoded( Client ID + ":" + Client Secret )

Body:

grant_type: urn:ietf:params:oauth:grant-type:jwt-bearer. assertion: JWT token.

Docs: https://developers.ringcentral.com/guide/authentication/jwt-flow

jmrbcu commented 7 months ago

This is the only way I've been able to do it:

session = OAuth2Session(self.client_id, self.client_secret)
session.fetch_token(urljoin(self.base_url, TOKEN_ENDPOINT), grant_type="urn:ietf:params:oauth:grant-type:jwt-bearer", assertion=jwt)
jlambright commented 7 months ago

I'm in the same boat, and it seems like the AssertionClient and AsyncAssertionClient don't take a signed jwt or even take in the private key. How is this supposed to work?

https://github.com/lepture/authlib/blob/master/authlib/integrations/httpx_client/assertion_client.py

jlambright commented 7 months ago

We were able to track down some implied keywords through reading the source code, but it didn't work.

self.assertion_client = AsyncAssertionClient(
                token_endpoint=f'https://{REDACTED_VARIABLE_1}/oauth/v2/token',
                subject=REDACTED_VARIABLE_2,
                issuer=REDACTED_VARIABLE_2,
                audience=f'https://{REDACTED_VARIABLE_1}',
                grant_type='urn:ietf:params:oauth:grant-type:jwt-bearer',
                token_placement='body',
                claims=self.scopes,
                header=REDACTED_VARIABLE_3,
                key=REDACTED_VARIABLE_4

            )