All Projects → AzureAD → Microsoft Authentication Library For Python

AzureAD / Microsoft Authentication Library For Python

Licence: other
Microsoft Authentication Library (MSAL) for Python makes it easy to authenticate to Azure Active Directory. These documented APIs are stable https://msal-python.readthedocs.io. If you have questions but do not have a github account, ask your questions on Stackoverflow with tag "msal" + "python".

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Microsoft Authentication Library For Python

Azure Gaming
Cloud Gaming Made Easy
Stars: ✭ 204 (-12.07%)
Mutual labels:  azure
Serverless Azure Functions
Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
Stars: ✭ 213 (-8.19%)
Mutual labels:  azure
Azure arc
Automated Azure Arc environments
Stars: ✭ 224 (-3.45%)
Mutual labels:  azure
Openapi Directory
🌐 Wikipedia for Web APIs. Directory of REST API definitions in OpenAPI 2.0/3.x format
Stars: ✭ 2,635 (+1035.78%)
Mutual labels:  azure
React Adal
Azure Active Directory Library (ADAL) support for ReactJS
Stars: ✭ 211 (-9.05%)
Mutual labels:  azure
Azure Functions Python Worker
Python worker for Azure Functions.
Stars: ✭ 221 (-4.74%)
Mutual labels:  azure
Azure Maven Plugins
Maven plugins for Azure
Stars: ✭ 203 (-12.5%)
Mutual labels:  azure
Azure Powershell
Microsoft Azure PowerShell
Stars: ✭ 2,873 (+1138.36%)
Mutual labels:  azure
Duplicacy Autobackup
💾 Painless automated backups to multiple storage providers with Docker and duplicacy.
Stars: ✭ 214 (-7.76%)
Mutual labels:  azure
Azure Batch Samples
Azure Batch and HPC Code Samples
Stars: ✭ 222 (-4.31%)
Mutual labels:  azure
Terraform Provider Azurerm
Terraform provider for Azure Resource Manager
Stars: ✭ 3,007 (+1196.12%)
Mutual labels:  azure
Blackbelt Aks Hackfest
Microsoft Intelligent Cloud Blackbelt Team :: Hackfest Repo
Stars: ✭ 209 (-9.91%)
Mutual labels:  azure
Usql
U-SQL Examples and Issue Tracking
Stars: ✭ 221 (-4.74%)
Mutual labels:  azure
Azure Cli
Azure Command-Line Interface
Stars: ✭ 2,862 (+1133.62%)
Mutual labels:  azure
Applicationinsights Node.js
Microsoft Application Insights SDK for Node.js
Stars: ✭ 229 (-1.29%)
Mutual labels:  azure
Azure Container Networking
Azure Container Networking Solutions for Linux and Windows Containers
Stars: ✭ 204 (-12.07%)
Mutual labels:  azure
Tfsec
Security scanner for your Terraform code
Stars: ✭ 3,622 (+1461.21%)
Mutual labels:  azure
Api Management Developer Portal
Azure API Management developer portal.
Stars: ✭ 229 (-1.29%)
Mutual labels:  azure
Kubestriker
A Blazing fast Security Auditing tool for Kubernetes
Stars: ✭ 213 (-8.19%)
Mutual labels:  azure
Applicationinsights Home
Application Insights main repository for documentation of overall SDK offerings for all platforms.
Stars: ✭ 221 (-4.74%)
Mutual labels:  azure

Microsoft Authentication Library (MSAL) for Python

dev branch Reference Docs # of Downloads
Build status Documentation Status Download monthly

The Microsoft Authentication Library for Python enables applications to integrate with the Microsoft identity platform. It allows you to sign in users or apps with Microsoft identities (Azure AD, Microsoft Accounts and Azure AD B2C accounts) and obtain tokens to call Microsoft APIs such as Microsoft Graph or your own APIs registered with the Microsoft identity platform. It is built using industry standard OAuth2 and OpenID Connect protocols

Not sure whether this is the SDK you are looking for your app? There are other Microsoft Identity SDKs here.

Quick links:

Getting Started Docs Samples Support

Installation

You can find MSAL Python on Pypi.

  1. If you haven't already, install and/or upgrade the pip of your Python environment to a recent version. We tested with pip 18.1.
  2. As usual, just run pip install msal.

Versions

This library follows Semantic Versioning.

You can find the changes for each version under Releases.

Usage

Before using MSAL Python (or any MSAL SDKs, for that matter), you will have to register your application with the Microsoft identity platform.

Acquiring tokens with MSAL Python follows this 3-step pattern. (Note: That is the high level conceptual pattern. There will be some variations for different flows. They are demonstrated in runnable samples hosted right in this repo. )

  1. MSAL proposes a clean separation between public client applications, and confidential client applications. So you will first create either a PublicClientApplication or a ConfidentialClientApplication instance, and ideally reuse it during the lifecycle of your app. The following example shows a PublicClientApplication:

    from msal import PublicClientApplication
    app = PublicClientApplication(
        "your_client_id",
        authority="https://login.microsoftonline.com/Enter_the_Tenant_Name_Here")
    

    Later, each time you would want an access token, you start by:

    result = None  # It is just an initial value. Please follow instructions below.
    
  2. The API model in MSAL provides you explicit control on how to utilize token cache. This cache part is technically optional, but we highly recommend you to harness the power of MSAL cache. It will automatically handle the token refresh for you.

    # We now check the cache to see
    # whether we already have some accounts that the end user already used to sign in before.
    accounts = app.get_accounts()
    if accounts:
        # If so, you could then somehow display these accounts and let end user choose
        print("Pick the account you want to use to proceed:")
        for a in accounts:
            print(a["username"])
        # Assuming the end user chose this one
        chosen = accounts[0]
        # Now let's try to find a token in cache for this account
        result = app.acquire_token_silent(["your_scope"], account=chosen)
    
  3. Either there is no suitable token in the cache, or you chose to skip the previous step, now it is time to actually send a request to AAD to obtain a token. There are different methods based on your client type and scenario. Here we demonstrate a placeholder flow.

    if not result:
        # So no suitable token exists in cache. Let's get a new one from AAD.
        result = app.acquire_token_by_one_of_the_actual_method(..., scopes=["User.Read"])
    if "access_token" in result:
        print(result["access_token"])  # Yay!
    else:
        print(result.get("error"))
        print(result.get("error_description"))
        print(result.get("correlation_id"))  # You may need this when reporting a bug
    

Refer the Wiki pages for more details on the MSAL Python functionality and usage.

Migrating from ADAL

If your application is using ADAL Python, we recommend you to update to use MSAL Python. No new feature work will be done in ADAL Python.

See the ADAL to MSAL migration guide.

Roadmap

You can follow the latest updates and plans for MSAL Python in the Roadmap published on our Wiki.

Samples and Documentation

MSAL Python supports multiple application types and authentication scenarios. The generic documents on Auth Scenarios and Auth protocols are recommended reading.

We provide a full suite of sample applications and documentation to help you get started with learning the Microsoft identity platform.

Community Help and Support

We leverage Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browser existing issues to see if someone has had your question before.

We recommend you use the "msal" tag so we can see it! Here is the latest Q&A on Stack Overflow for MSAL: http://stackoverflow.com/questions/tagged/msal

Security Reporting

If you find a security issue with our libraries or services please report it to [email protected] with as much detail as possible. Your submission may be eligible for a bounty through the Microsoft Bounty program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting this page and subscribing to Security Advisory Alerts.

Contributing

All code is licensed under the MIT license and we triage actively on GitHub. We enthusiastically welcome contributions and feedback. Please read the contributing guide before starting.

We Value and Adhere to the Microsoft Open Source Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].