Skip to main content

A library to get MSAL token interactively for native client.

Project description

Wheel PyPI version

MSAL Interactive Token Acquirer

This is a library to acquire Microsoft OAuth2 access token interactively.

Overview

This library supports interactive authentication.
If you need a library for non-interactive authentication, you can use MSAL for python, which supports many authentication flows.

How to use

Basic usage

You can acquire Microsoft OAuth2 access token interactively as follows:

from msal_interactive_token_acquirer import MsalInteractiveTokenAcquirer

tenant = "common"
client_id = "5d2a0ea0-a46a-4626-835e-04e13f75fed0"
scopes = ["User.Read"]
msal = MsalInteractiveTokenAcquirer(tenant, client_id, scopes)
msal.acquire_token_interactively()  # (*1)
msal.access_token()
# => This returns Bearer token.

Note that the redirect URI of the application must be "https://login.microsoftonline.com/common/oauth2/nativeclient".
This shows the following window at (*1).
window

You can save and load MsalInteractiveTokenAcquirer as follows:

from msal_interactive_token_acquirer import MsalInteractiveTokenAcquirer
import pickle

# ...snip...

# msal is an instance of MsalInteractiveTokenAcquirer.
with open("msal.pickle", "wb") as f:
    pickle.dump(msal, f)

# ...snip...

with open("msal.pickle", "rb") as f:
    msal = pickle.load(f)
msal.access_token()
# => This returns Bearer token.

Authentication with Requests HTTP library

You can use this library for authentication with Requests as follows:

from msal_interactive_token_acquirer import MsalInteractiveTokenAcquirer
from msal_interactive_token_acquirer.requests_auth import MsalAuth
import requests

msal = MsalInteractiveTokenAcquirer("...", "...", ["..."])
msal.acquire_token_interactively()

auth = MsalAuth(msal)
response = requests.get("https://......", auth=auth)

Or, you can use MsalSession like requests.Session as follows:

from msal_interactive_token_acquirer import MsalInteractiveTokenAcquirer
from msal_interactive_token_acquirer.requests import MsalSession

msal = MsalInteractiveTokenAcquirer("...", "...", ["..."])
msal.acquire_token_interactively()

session = MsalSession(msal)
response = session.get("https://......")

License

You can use this library under the MIT License.

Copyright 2020 Masamitsu MURASE

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

msal_interactive_token_acquirer-1.4.0-py3-none-win_amd64.whl (1.1 MB view details)

Uploaded Python 3 Windows x86-64

File details

Details for the file msal_interactive_token_acquirer-1.4.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: msal_interactive_token_acquirer-1.4.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for msal_interactive_token_acquirer-1.4.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a1564043b909b86b75ef27d54bb67f7f8a85f1f23319556595282fd306eeedc4
MD5 6774a5093792f4281af8a1fde0d0947b
BLAKE2b-256 43517ac48239719f3e07dd06d0617df17cac7727546b96cefe22f8aee35e0865

See more details on using hashes here.

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