Search code examples
authlib

authlib: some client_kwargs in config are not used


Love authlib overall. Question about client_kwargs described in https://docs.authlib.org/en/latest/client/frameworks.html and https://docs.authlib.org/en/latest/client/django.html

Problem statement: I tried to pass "scope" and "audience" key/value pairs in the client_kwargs dict, but only "scope" key/value is used for generating URI for authorization. I need to pass "audience" for Atlassian OAuth2.0 https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/

Workaround found after some tinkering by passing "audience"="api.atlassian.com" to oauth.atlassian.authorize_redirect.

Question: Is client_kwargs in oauth.register/AUTHLIB_OAUTH_CLIENTS intended only for certain keyword arguments? If so, would be great to share it in the documentation; otherwise it would be convenient to set it in config together with everything else.

This behavior was found in 0.12.1 and 0.13.dev0. Thanks!


Solution

  • Because OAuth 1.0 and OAuth 2.0 are different, this client_kwargs are designed to pass extra parameters to either OAuth1Client/OAuth1Session or OAuth2Client/OAuth2Session.

    For your case, there is a authorize_params. You can put audience in your authorize_params:

    oauth.register(
        ....
        authorize_params={'audience': '...'},
        ....
    )