AdalAuthentication Class

A wrapper to use ADAL for Python easily to authenticate on Azure.

New in version 0.4.5.

Take an ADAL acquire_token method and its parameters.


   context = adal.AuthenticationContext('https://login.microsoftonline.com/ABCDEFGH-1234-1234-1234-ABCDEFGHIJKL')
   RESOURCE = '00000002-0000-0000-c000-000000000000' #AAD graph resource
   token = context.acquire_token_with_client_credentials(
       RESOURCE,
       "http://PythonSDK",
       "Key-Configured-In-Portal")

can be written here:


   context = adal.AuthenticationContext('https://login.microsoftonline.com/ABCDEFGH-1234-1234-1234-ABCDEFGHIJKL')
   RESOURCE = '00000002-0000-0000-c000-000000000000' #AAD graph resource
   credentials = AdalAuthentication(
       context.acquire_token_with_client_credentials,
       RESOURCE,
       "http://PythonSDK",
       "Key-Configured-In-Portal")

or using a lambda if you prefer:


   context = adal.AuthenticationContext('https://login.microsoftonline.com/ABCDEFGH-1234-1234-1234-ABCDEFGHIJKL')
   RESOURCE = '00000002-0000-0000-c000-000000000000' #AAD graph resource
   credentials = AdalAuthentication(
       lambda: context.acquire_token_with_client_credentials(
           RESOURCE,
           "http://PythonSDK",
           "Key-Configured-In-Portal"
       )
   )
Inheritance
AdalAuthentication

Constructor

AdalAuthentication(adal_method, *args, **kwargs)

Parameters

adal_method
callable
Required

A lambda with no args, or acquire_token method with args using args/kwargs

args
Required

Optional positional args for the method

kwargs
Required

Optional kwargs for the method

Methods

signed_session

Create requests session with any required auth headers applied.

If a session object is provided, configure it directly. Otherwise, create a new session and return it.

signed_session

Create requests session with any required auth headers applied.

If a session object is provided, configure it directly. Otherwise, create a new session and return it.

signed_session(session=None)

Parameters

session
<xref:requests.Session>
default value: None

The session to configure for authentication

Return type

<xref:requests.Session>