AzureAD / microsoft-authentication-library-for-python

Microsoft Authentication Library (MSAL) for Python makes it easy to authenticate to Microsoft Entra ID. General docs are available here https://learn.microsoft.com/entra/msal/python/ Stable APIs are documented here https://msal-python.readthedocs.io. Questions can be asked on www.stackoverflow.com with tag "msal" + "python".
https://stackoverflow.com/questions/tagged/azure-ad-msal+python
Other
790 stars 194 forks source link

Add close method to app #371

Open HansWeltar opened 3 years ago

HansWeltar commented 3 years ago

Fixes Issue #370 Session/socket never closed, warnings shown

The msal application does not close it's resources like eg: self.http_client. As a result a 'ResourceWarning unclosed <ssl.SSLSocket' is shown when the app goes out of scope (when warnings are enabled)

This fix adds and explicit close method so developpers can cleanly close the app if they so desire.

HansWeltar commented 3 years ago

A better fix might be needed. A close() method does not help in case of __init__ errors. For example when you provide a wrong tenant_id

try:
    app = msal.application.ConfidentialClientApplication(APPID, client_credential=SECRET, 
        authority="https://login.microsoftonline.com/" + FAULTY_TENANT)
except Exception:
    app.close() -> fails because app is not defined....
ghost commented 3 years ago

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

:x: HansWeltar sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

HansWeltar commented 3 years ago

adressed

A better fix might be needed. A close() method does not help in case of init errors. For example when you provide a wrong tenant_id

try:
    app = msal.application.ConfidentialClientApplication(APPID, client_credential=SECRET, 
        authority="https://login.microsoftonline.com/" + FAULTY_TENANT)
except Exception:
    app.close() -> fails because app is not defined....
bgavrilMS commented 11 months ago

Seems like the original issue still exists? Is this PR valid?