Skip to main content

Authentication using python requests and MSAL

Project description

Authentication using python requests and MSAL. This uses the MSAL cache for repeated requests.

All Contributors https://img.shields.io/badge/License-BSD%203--Clause-yellow.svg https://img.shields.io/pypi/v/msal_requests_auth.svg https://pepy.tech/badge/msal_requests_auth https://img.shields.io/conda/vn/conda-forge/msal_requests_auth.svg https://github.com/corteva/msal-requests-auth/workflows/Tests/badge.svg https://codecov.io/gh/corteva/msal-requests-auth/branch/master/graph/badge.svg https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white https://img.shields.io/badge/code%20style-black-000000.svg

Bugs/Questions

Usage

Device Code Flow

import requests
import msal
from msal_requests_auth.auth import DeviceCodeAuth

client_id = "<client ID from Azure AD>"
tenant_id = "<tenant ID from Azure AD>"
application_id = "<client ID of application you want to get a token for from Azure AD>"
app = msal.PublicClientApplication(
    client_id,
    authority=f"https://login.microsoftonline.com/{tenant_id}/",
)
auth = DeviceCodeAuth(
    client=app,
    scopes=[f"{application_id}/.default"],
)
response = requests.get(
    endpoint,
    auth=auth,
)

Client Credentials Flow

import requests
import msal
from msal_requests_auth.auth import ClientCredentialAuth

client_id = "<client ID from Azure AD>"
client_secret = "<client secret for client in Azure AD>"
tenant_id = "<tenant ID from Azure AD>"
application_id = "<client ID of application you want to get a token for from Azure AD>"
app = msal.ConfidentialClientApplication(
    client_id,
    authority=(f"https://login.microsoftonline.com/{tenant_id}/"),
    client_credential=client_secret,
)
auth = ClientCredentialAuth(
    client=app,
    scopes=[f"{application_id}/.default"],
)
response = requests.get(
    endpoint,
    auth=auth,
)

Installation

To install msal-requests-auth, run this command in your terminal:

$ python -m pip install msal_requests_auth

If you use conda:

$ conda install -c conda-forge msal_requests_auth

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msal_requests_auth-0.3.0.tar.gz (10.9 kB view details)

Uploaded Source

File details

Details for the file msal_requests_auth-0.3.0.tar.gz.

File metadata

  • Download URL: msal_requests_auth-0.3.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for msal_requests_auth-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7e6b1d4fe42ac37a845e666cfea9efca3914c83eaa882797c7549299bf22b44a
MD5 a7817373e73fc47d60d6ebc06dd23067
BLAKE2b-256 0e7ac91de85f88d5e9c4ce38a33c2ecd741cb7cab979b17f2654ccf3bf3a4321

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page