Search code examples
pythonssloauthauthlib

Authlib SSLError with self signed certs


I'm using authlib with the following code:


session = OAuth2Session(client_id, client_secret)

token = session.fetch_access_token(
    access_token_url,
    client_id='.....',
    method='POST',
    client_secret=client_secret,
    authorization_response=request.url,
    code=request.args['code']
)

Which yelds a requests.exceptions.SSLError (CERTIFICATE_VERIFY_FAILED) when trying to access to my own OAuth2 server with self-signed certificates.

What should I do to use HTTPS regardless of this error ?


Solution

  • There are two ways:

    1. pass verify=False, which won't validate the SSL
    2. pass `cert="path to ssl client cert file (.pem)"

    OAuth2Session.fetch_access_token accepts all parameters supported by requests. Check requests API documentation: https://2.python-requests.org/en/master/api/#requests.request