GithubHelp home page GithubHelp logo

rcplay / azure-activedirectory-library-for-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azuread/azure-activedirectory-library-for-python

0.0 2.0 0.0 392 KB

ADAL for Python

License: Other

Python 100.00%

azure-activedirectory-library-for-python's Introduction

Microsoft Azure Active Directory Authentication Library (ADAL) for Python

The ADAL for python library makes it easy for python applications to authenticate to AAD in order to access AAD protected web resources.

Note

This is an early, pre-release version of the library. It does not yet have support for any kind of caching.

Usage

Acquire Token with Username & Password

import adal
token_response = adal.acquire_token_with_username_password(
    'https://login.windows.net/ACTIVE_DIRECTORY_TENANT.onmicrosoft.com',
    'username@ACTIVE_DIRECTORY_TENANT.onmicrosoft.com',
    'password'
)

Acquire Token with Client Credentials

In order to use this token acquisition method, you need to:

  1. Create an Azure Active Directory (AD) instance on your Azure account

  2. Create an application in the AD instance and name it PythonSDK http://PythonSDK

  3. Go to the configure tab and you can find all of the following information:

  • Click on 'View Endpoints' and Copy the 'Federation Metadata Document' entry. The Root + GUID URL is our Authority.
  • Exit out of App Endpoints. The Client ID is on the configure page.
  • In the keys section of the Azure AD App Configure page, create a key (1 or 2 years is fine)
import adal
token_response = adal.acquire_token_with_client_credentials(
    "https://login.microsoftonline.com/ABCDEFGH-1234-1234-1234-ABCDEFGHIJKL", # Authority
    "ABCDEFGH-1234-1234-1234-ABCDEFGHIJKL", # Client ID
    "a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a=" # Client Secret
)

If you are using this with the Azure SDK, you will need to give the PythonSDK application we have access. From powershell you can execute the following:

Switch-AzureMode -Name AzureResourceManager
Add-AzureAccount # This will pop up a login dialog
# Look at the subscriptions returned and put one on the line below
Select-AzureSubscription -SubscriptionId ABCDEFGH-1234-1234-1234-ABCDEFGH
New-AzureRoleAssignment -ServicePrincipalName http://PythonSDK -RoleDefinitionName Contributor

Acquire Token with Refresh Token

import adal
token_response = adal.acquire_token_with_username_password(
    'https://login.windows.net/ACTIVE_DIRECTORY_TENANT.onmicrosoft.com',
    'username@ACTIVE_DIRECTORY_TENANT.onmicrosoft.com',
    'password'

# Use returned refresh token to acquire a new token.
refresh_token = token_response['refreshToken']
token_response = adal.acquire_token_with_refresh_token(authority, refresh_token)

Samples and Documentation

We provide a full suite of sample applications and documentation on GitHub to help you get started with learning the Azure Identity system. This includes tutorials for native clients such as Windows, Windows Phone, iOS, OSX, Android, and Linux. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect, Graph API, and other awesome features.

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 "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: http://stackoverflow.com/questions/tagged/adal

Contributing

All code is licensed under the MIT license and we triage actively on GitHub. We enthusiastically welcome contributions and feedback. You can clone the repo and start contributing now.

Quick Start

Installation

$ pip install adal

azure-activedirectory-library-for-python's People

Contributors

annatisch avatar crwilcox avatar randallilama avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.