Skip to content

Release 1.14.0 #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f53699f
Explicitly add license file
rayluo Jul 17, 2021
7218aaf
Merge pull request #384 from AzureAD/release-1.13.0
rayluo Jul 20, 2021
3bd1a9d
Use dot-env for convenient local testing
rayluo Jul 15, 2021
89a10d4
Merge branch 'dot-env' into dev
rayluo Jul 23, 2021
ab1f353
It was skipped and recently broken. Now it works.
rayluo Jul 30, 2021
9309743
Merge branch 'worldwide-confidential-client-test' into dev
rayluo Jul 30, 2021
ffc5953
Switch to github action badge
rayluo Jul 8, 2021
efbc83a
Merge branch 'switch-to-github-action-badge' into dev
rayluo Aug 1, 2021
db6f001
Survive issue 387
rayluo Aug 4, 2021
ee96522
Merge pull request #390 from AzureAD/fix-issue-387
rayluo Aug 4, 2021
4398d23
obtain_token_by_browser(..., error_template=...)
rayluo Mar 26, 2021
4f2f2de
Merge branch 'error_template' into dev
rayluo Mar 29, 2021
c89f193
Customizable browser_name
rayluo Mar 31, 2021
bbb9af5
Merge branch 'customizable-browser' into dev
rayluo Apr 5, 2021
efa5668
Merge in staged oauth2cli changes
rayluo Aug 5, 2021
e94dda5
Merge branch 'o2c' into dev
rayluo Aug 5, 2021
bce6cc0
Turns out webbrowser.open() is more robust
rayluo Apr 8, 2021
ed4c796
Merge branch 'customizable-browser' into dev
rayluo Apr 12, 2021
c687d5b
Merge remote-tracking branch 'oauth2cli_github/dev' into o2c
rayluo Aug 5, 2021
71802d0
Change regional endpoint doname name
rayluo Aug 10, 2021
96140b0
Regional endpoint test cases do not rely on env var REGION_NAME
rayluo Aug 10, 2021
5fdae2d
REGION_NAME has no unified format across services
rayluo Aug 10, 2021
3e2b56d
Merge pull request #394 from AzureAD/region-endpoint-specs-changes
rayluo Aug 10, 2021
f565493
Prefer Edge when running on Linux
rayluo Jul 30, 2021
ef89877
Merge pull request #388 from AzureAD/prefer-edge-on-linux
rayluo Aug 19, 2021
27097e6
An individual cache, after 3+ prototypes
rayluo May 7, 2020
e33b055
ThrottledHttpClient
rayluo Jul 8, 2021
b4401a1
Use throttled_http_client
rayluo Jul 8, 2021
deb7900
Merge pull request #379 from AzureAD/http-cache
rayluo Aug 19, 2021
8eb5c18
Convert staticmethod to module-wide public method
rayluo Aug 18, 2021
e969e64
Merge branch 'refactor-token-cache-test-cases' into dev
rayluo Aug 19, 2021
a1f9ca7
Enable ThrottledHttpClient.close()
rayluo Aug 26, 2021
a621e50
Merge branch 'http-cache' into dev
rayluo Aug 26, 2021
24959a9
MSAL Python 1.14
rayluo Aug 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ docs/_build/
# The test configuration file(s) could potentially contain credentials
tests/config.json


.env
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Microsoft Authentication Library (MSAL) for Python


| `dev` branch | Reference Docs | # of Downloads per different platforms | # of Downloads per recent MSAL versions |
|---------------|---------------|----------------------------------------|-----------------------------------------|
[![Build status](https://api.travis-ci.org/AzureAD/microsoft-authentication-library-for-python.svg?branch=dev)](https://travis-ci.org/AzureAD/microsoft-authentication-library-for-python) | [![Documentation Status](https://readthedocs.org/projects/msal-python/badge/?version=latest)](https://msal-python.readthedocs.io/en/latest/?badge=latest) | [![Downloads](https://pepy.tech/badge/msal)](https://pypistats.org/packages/msal) | [![Download monthly](https://pepy.tech/badge/msal/month)](https://pepy.tech/project/msal)
[![Build status](https://github.com/AzureAD/microsoft-authentication-library-for-python/actions/workflows/python-package.yml/badge.svg?branch=dev)](https://github.com/AzureAD/microsoft-authentication-library-for-python/actions) | [![Documentation Status](https://readthedocs.org/projects/msal-python/badge/?version=latest)](https://msal-python.readthedocs.io/en/latest/?badge=latest) | [![Downloads](https://pepy.tech/badge/msal)](https://pypistats.org/packages/msal) | [![Download monthly](https://pepy.tech/badge/msal/month)](https://pepy.tech/project/msal)

The Microsoft Authentication Library for Python enables applications to integrate with the [Microsoft identity platform](https://aka.ms/aaddevv2). It allows you to sign in users or apps with Microsoft identities ([Azure AD](https://azure.microsoft.com/services/active-directory/), [Microsoft Accounts](https://account.microsoft.com) and [Azure AD B2C](https://azure.microsoft.com/services/active-directory-b2c/) accounts) and obtain tokens to call Microsoft APIs such as [Microsoft Graph](https://graph.microsoft.io/) or your own APIs registered with the Microsoft identity platform. It is built using industry standard OAuth2 and OpenID Connect protocols

Expand Down
52 changes: 50 additions & 2 deletions msal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import warnings
from threading import Lock
import os

import requests

Expand All @@ -20,10 +21,11 @@
from .token_cache import TokenCache
import msal.telemetry
from .region import _detect_region
from .throttled_http_client import ThrottledHttpClient


# The __init__.py will import this. Not the other way around.
__version__ = "1.13.0"
__version__ = "1.14.0"

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -69,6 +71,46 @@ def _clean_up(result):
return result


def _preferred_browser():
"""Register Edge and return a name suitable for subsequent webbrowser.get(...)
when appropriate. Otherwise return None.
"""
# On Linux, only Edge will provide device-based Conditional Access support
if sys.platform != "linux": # On other platforms, we have no browser preference
return None
browser_path = "/usr/bin/microsoft-edge" # Use a full path owned by sys admin
user_has_no_preference = "BROWSER" not in os.environ
user_wont_mind_edge = "microsoft-edge" in os.environ.get("BROWSER", "") # Note:
# BROWSER could contain "microsoft-edge" or "/path/to/microsoft-edge".
# Python documentation (https://docs.python.org/3/library/webbrowser.html)
# does not document the name being implicitly register,
# so there is no public API to know whether the ENV VAR browser would work.
# Therefore, we would not bother examine the env var browser's type.
# We would just register our own Edge instance.
if (user_has_no_preference or user_wont_mind_edge) and os.path.exists(browser_path):
try:
import webbrowser # Lazy import. Some distro may not have this.
browser_name = "msal-edge" # Avoid popular name "microsoft-edge"
# otherwise `BROWSER="microsoft-edge"; webbrowser.get("microsoft-edge")`
# would return a GenericBrowser instance which won't work.
try:
registration_available = isinstance(
webbrowser.get(browser_name), webbrowser.BackgroundBrowser)
except webbrowser.Error:
registration_available = False
if not registration_available:
logger.debug("Register %s with %s", browser_name, browser_path)
# By registering our own browser instance with our own name,
# rather than populating a process-wide BROWSER enn var,
# this approach does not have side effect on non-MSAL code path.
webbrowser.register( # Even double-register happens to work fine
browser_name, None, webbrowser.BackgroundBrowser(browser_path))
return browser_name
except ImportError:
pass # We may still proceed
return None


class ClientApplication(object):

ACQUIRE_TOKEN_SILENT_ID = "84"
Expand Down Expand Up @@ -295,6 +337,10 @@ def __init__(
a = requests.adapters.HTTPAdapter(max_retries=1)
self.http_client.mount("http://", a)
self.http_client.mount("https://", a)
self.http_client = ThrottledHttpClient(
self.http_client,
{} # Hard code an in-memory cache, for now
)

self.app_name = app_name
self.app_version = app_version
Expand Down Expand Up @@ -371,7 +417,7 @@ def _get_regional_authority(self, central_authority):
self._region_configured if is_region_specified else self._region_detected)
if region_to_use:
logger.info('Region to be used: {}'.format(repr(region_to_use)))
regional_host = ("{}.login.microsoft.com".format(region_to_use)
regional_host = ("{}.r.login.microsoftonline.com".format(region_to_use)
if central_authority.instance in (
# The list came from https://github.com/AzureAD/microsoft-authentication-library-for-python/pull/358/files#r629400328
"login.microsoftonline.com",
Expand All @@ -392,6 +438,7 @@ def _build_client(self, client_credential, authority, skip_regional_client=False
"x-client-sku": "MSAL.Python", "x-client-ver": __version__,
"x-client-os": sys.platform,
"x-client-cpu": "x64" if sys.maxsize > 2 ** 32 else "x86",
"x-ms-lib-capability": "retry-after, h429",
}
if self.app_name:
default_headers['x-app-name'] = self.app_name
Expand Down Expand Up @@ -1393,6 +1440,7 @@ def acquire_token_interactive(
},
data=dict(kwargs.pop("data", {}), claims=claims),
headers=telemetry_context.generate_headers(),
browser_name=_preferred_browser(),
**kwargs))
telemetry_context.update_telemetry(response)
return response
Expand Down
Loading