Skip to content

Commit c1fedad

Browse files
committed
Merge branch 'dev' into bugfix-token-cache-search
2 parents e80b58f + c1ead1c commit c1fedad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2065
-521
lines changed

.github/workflows/python-package.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
TRAVIS: true
1919
LAB_APP_CLIENT_ID: ${{ secrets.LAB_APP_CLIENT_ID }}
2020
LAB_APP_CLIENT_SECRET: ${{ secrets.LAB_APP_CLIENT_SECRET }}
21+
LAB_APP_CLIENT_CERT_BASE64: ${{ secrets.LAB_APP_CLIENT_CERT_BASE64 }}
22+
LAB_APP_CLIENT_CERT_PFX_PATH: lab_cert.pfx
2123
LAB_OBO_CLIENT_SECRET: ${{ secrets.LAB_OBO_CLIENT_SECRET }}
2224
LAB_OBO_CONFIDENTIAL_CLIENT_ID: ${{ secrets.LAB_OBO_CONFIDENTIAL_CLIENT_ID }}
2325
LAB_OBO_PUBLIC_CLIENT_ID: ${{ secrets.LAB_OBO_PUBLIC_CLIENT_ID }}
@@ -31,17 +33,21 @@ jobs:
3133
steps:
3234
- uses: actions/checkout@v4
3335
- name: Set up Python ${{ matrix.python-version }}
34-
uses: actions/setup-python@v4
36+
uses: actions/setup-python@v5
3537
# It automatically takes care of pip cache, according to
3638
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#about-caching-workflow-dependencies
3739
with:
3840
python-version: ${{ matrix.python-version }}
41+
cache: 'pip'
3942

4043
- name: Install dependencies
4144
run: |
4245
python -m pip install --upgrade pip
4346
python -m pip install flake8 pytest
4447
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
48+
- name: Populate lab cert.pfx
49+
# https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#storing-base64-binary-blobs-as-secrets
50+
run: echo $LAB_APP_CLIENT_CERT_BASE64 | base64 -d > $LAB_APP_CLIENT_CERT_PFX_PATH
4551
- name: Test with pytest
4652
run: pytest --benchmark-skip
4753
- name: Lint with flake8
@@ -56,18 +62,21 @@ jobs:
5662
# and then run benchmark only once (sampling with only one Python version).
5763
needs: ci
5864
runs-on: ubuntu-latest
65+
permissions:
66+
contents: write
5967
steps:
6068
- uses: actions/checkout@v4
6169
- name: Set up Python 3.9
62-
uses: actions/setup-python@v4
70+
uses: actions/setup-python@v5
6371
with:
6472
python-version: 3.9
73+
cache: 'pip'
6574
- name: Install dependencies
6675
run: |
6776
python -m pip install --upgrade pip
6877
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
6978
- name: Setup an updatable cache for Performance Baselines
70-
uses: actions/cache@v3
79+
uses: actions/cache@v4
7180
with:
7281
path: .perf.baseline
7382
key: ${{ runner.os }}-performance-${{ hashFiles('tests/test_benchmark.py') }}
@@ -99,9 +108,10 @@ jobs:
99108
steps:
100109
- uses: actions/checkout@v4
101110
- name: Set up Python 3.9
102-
uses: actions/setup-python@v4
111+
uses: actions/setup-python@v5
103112
with:
104113
python-version: 3.9
114+
cache: 'pip'
105115
- name: Build a package for release
106116
run: |
107117
python -m pip install build --user

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @AzureAD/id4s-msal-team

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
|:------------:|:--------------:|:--------------------------------------:|:---------------------------------------:|:-----------------:|
55
[![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://static.pepy.tech/badge/msal)](https://pypistats.org/packages/msal) | [![Download monthly](https://static.pepy.tech/badge/msal/month)](https://pepy.tech/project/msal) | [📉](https://azuread.github.io/microsoft-authentication-library-for-python/dev/bench/)
66

7-
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
7+
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 ([Microsoft Entra ID](https://www.microsoft.com/security/business/identity-access/microsoft-entra-id), [External identities](https://www.microsoft.com/security/business/identity-access/microsoft-entra-external-id), [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
88

99
Not sure whether this is the SDK you are looking for your app? There are other Microsoft Identity SDKs
1010
[here](https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Microsoft-Authentication-Client-Libraries).
@@ -23,9 +23,10 @@ Click on the following thumbnail to visit a large map with clickable links to pr
2323
## Installation
2424

2525
You can find MSAL Python on [Pypi](https://pypi.org/project/msal/).
26+
2627
1. If you haven't already, [install and/or upgrade the pip](https://pip.pypa.io/en/stable/installing/)
2728
of your Python environment to a recent version. We tested with pip 18.1.
28-
2. As usual, just run `pip install msal`.
29+
1. As usual, just run `pip install msal`.
2930

3031
## Versions
3132

@@ -123,7 +124,7 @@ We provide a [full suite of sample applications](https://aka.ms/aaddevsamplesv2)
123124

124125
## Community Help and Support
125126

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

@@ -132,6 +133,7 @@ Here is the latest Q&A on Stack Overflow for MSAL:
132133
[http://stackoverflow.com/questions/tagged/msal](http://stackoverflow.com/questions/tagged/msal)
133134

134135
## Submit Feedback
136+
135137
We'd like your thoughts on this library. Please complete [this short survey.](https://forms.office.com/r/TMjZkDbzjY)
136138

137139
## Security Reporting

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#
6363
# This is also used if you do content translation via gettext catalogs.
6464
# Usually you set "language" from the command line for these cases.
65-
language = None
65+
language = "en"
6666

6767
# List of patterns, relative to source directory, that match files and
6868
# directories to ignore when looking for source files.
@@ -95,7 +95,7 @@
9595
# Add any paths that contain custom static files (such as style sheets) here,
9696
# relative to this directory. They are copied after the builtin static files,
9797
# so a file named "default.css" will overwrite the builtin "default.css".
98-
html_static_path = ['_static']
98+
#html_static_path = ['_static']
9999

100100
# Custom sidebar templates, must be a dictionary that maps document names
101101
# to template names.

docs/index.rst

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
=========================
12
MSAL Python Documentation
23
=========================
34

@@ -6,11 +7,11 @@ MSAL Python Documentation
67
:caption: Contents:
78
:hidden:
89

9-
index
10-
1110
..
1211
Comment: Perhaps because of the theme, only the first level sections will show in TOC,
1312
regardless of maxdepth setting.
13+
UPDATE: And now (early 2024) suddenly a function-level, long TOC is generated,
14+
even though maxdepth is set to 2.
1415
1516
You can find high level conceptual documentations in the project
1617
`README <https://github.com/AzureAD/microsoft-authentication-library-for-python>`_.
@@ -23,7 +24,7 @@ MSAL Python supports some of them.
2324
**The following diagram serves as a map. Locate your application scenario on the map.**
2425
**If the corresponding icon is clickable, it will bring you to an MSAL Python sample for that scenario.**
2526

26-
* Most authentication scenarios acquire tokens on behalf of signed-in users.
27+
* Most authentication scenarios acquire tokens representing the signed-in user.
2728

2829
.. raw:: html
2930

@@ -43,7 +44,7 @@ MSAL Python supports some of them.
4344
alt="Browserless app" title="Browserless app" href="https://github.com/Azure-Samples/ms-identity-python-devicecodeflow">
4445
</map>
4546

46-
* There are also daemon apps. In these scenarios, applications acquire tokens on behalf of themselves with no user.
47+
* There are also daemon apps, who acquire tokens representing themselves, not a user.
4748

4849
.. raw:: html
4950

@@ -63,26 +64,24 @@ MSAL Python supports some of them.
6364

6465
API Reference
6566
=============
67+
.. note::
68+
69+
Only the contents inside
70+
`this source file <https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/dev/msal/__init__.py>`_
71+
and their documented methods (unless otherwise marked as deprecated)
72+
are MSAL Python public API,
73+
which are guaranteed to be backward-compatible until the next major version.
74+
75+
Everything else, regardless of their naming, are all internal helpers,
76+
which could change at anytime in the future, without prior notice.
6677

6778
The following section is the API Reference of MSAL Python.
68-
The API Reference is like a dictionary. You **read this API section when and only when**:
79+
The API Reference is like a dictionary, which is useful when:
6980

7081
* You already followed our sample(s) above and have your app up and running,
7182
but want to know more on how you could tweak the authentication experience
7283
by using other optional parameters (there are plenty of them!)
73-
* You read the MSAL Python source code and found a helper function that is useful to you,
74-
then you would want to double check whether that helper is documented below.
75-
Only documented APIs are considered part of the MSAL Python public API,
76-
which are guaranteed to be backward-compatible in MSAL Python 1.x series.
77-
Undocumented internal helpers are subject to change anytime, without prior notice.
78-
79-
.. note::
80-
81-
Only APIs and their parameters documented in this section are part of public API,
82-
with guaranteed backward compatibility for the entire 1.x series.
83-
84-
Other modules in the source code are all considered as internal helpers,
85-
which could change at anytime in the future, without prior notice.
84+
* Some important features have their in-depth documentations in the API Reference.
8685

8786
MSAL proposes a clean separation between
8887
`public client applications and confidential client applications
@@ -92,7 +91,7 @@ They are implemented as two separated classes,
9291
with different methods for different authentication scenarios.
9392

9493
ClientApplication
95-
=================
94+
-----------------
9695

9796
.. autoclass:: msal.ClientApplication
9897
:members:
@@ -101,22 +100,23 @@ ClientApplication
101100
.. automethod:: __init__
102101

103102
PublicClientApplication
104-
=======================
103+
-----------------------
105104

106105
.. autoclass:: msal.PublicClientApplication
107106
:members:
108107

108+
.. autoattribute:: msal.PublicClientApplication.CONSOLE_WINDOW_HANDLE
109109
.. automethod:: __init__
110110

111111
ConfidentialClientApplication
112-
=============================
112+
-----------------------------
113113

114114
.. autoclass:: msal.ConfidentialClientApplication
115115
:members:
116116

117117

118118
TokenCache
119-
==========
119+
----------
120120

121121
One of the parameters accepted by
122122
both `PublicClientApplication` and `ConfidentialClientApplication`
@@ -130,3 +130,61 @@ See `SerializableTokenCache` for example.
130130

131131
.. autoclass:: msal.SerializableTokenCache
132132
:members:
133+
134+
Prompt
135+
------
136+
.. autoclass:: msal.Prompt
137+
:members:
138+
139+
.. autoattribute:: msal.Prompt.SELECT_ACCOUNT
140+
.. autoattribute:: msal.Prompt.NONE
141+
.. autoattribute:: msal.Prompt.CONSENT
142+
.. autoattribute:: msal.Prompt.LOGIN
143+
144+
PopAuthScheme
145+
-------------
146+
147+
This is used as the `auth_scheme` parameter in many of the acquire token methods
148+
to support for Proof of Possession (PoP) tokens.
149+
150+
New in MSAL Python 1.26
151+
152+
.. autoclass:: msal.PopAuthScheme
153+
:members:
154+
155+
.. autoattribute:: msal.PopAuthScheme.HTTP_GET
156+
.. autoattribute:: msal.PopAuthScheme.HTTP_POST
157+
.. autoattribute:: msal.PopAuthScheme.HTTP_PUT
158+
.. autoattribute:: msal.PopAuthScheme.HTTP_DELETE
159+
.. autoattribute:: msal.PopAuthScheme.HTTP_PATCH
160+
.. automethod:: __init__
161+
162+
163+
Exceptions
164+
----------
165+
These are exceptions that MSAL Python may raise.
166+
You should not need to create them directly.
167+
You may want to catch them to provide a better error message to your end users.
168+
169+
.. autoclass:: msal.IdTokenError
170+
171+
172+
Managed Identity
173+
================
174+
MSAL supports
175+
`Managed Identity <https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview>`_.
176+
177+
You can create one of these two kinds of managed identity configuration objects:
178+
179+
.. autoclass:: msal.SystemAssignedManagedIdentity
180+
:members:
181+
182+
.. autoclass:: msal.UserAssignedManagedIdentity
183+
:members:
184+
185+
And then feed the configuration object into a :class:`ManagedIdentityClient` object.
186+
187+
.. autoclass:: msal.ManagedIdentityClient
188+
:members:
189+
190+
.. automethod:: __init__

msal/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@
3131
ConfidentialClientApplication,
3232
PublicClientApplication,
3333
)
34-
from .oauth2cli.oidc import Prompt
34+
from .oauth2cli.oidc import Prompt, IdTokenError
3535
from .token_cache import TokenCache, SerializableTokenCache
3636
from .auth_scheme import PopAuthScheme
37+
from .managed_identity import (
38+
SystemAssignedManagedIdentity, UserAssignedManagedIdentity,
39+
ManagedIdentityClient,
40+
ManagedIdentityError,
41+
ArcPlatformNotSupportedError,
42+
)
43+
44+
# Putting module-level exceptions into the package namespace, to make them
45+
# 1. officially part of the MSAL public API, and
46+
# 2. can still be caught by the user code even if we change the module structure.
47+
from .oauth2cli.oauth2 import BrowserInteractionTimeoutError
3748

0 commit comments

Comments
 (0)