You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the documentation repository for Microsoft Authentication Library (MSAL) for .NET. If you are looking for the library, refer to [AzureAD/microsoft-authentication-library-for-python](https://github.com/AzureAD/microsoft-authentication-library-for-python).
6
+
7
+
## Contributions
8
+
9
+
Contributions to our documentation are welcome. Make sure to familiarize yourself with the [Microsoft Writing Style Guide](https://learn.microsoft.com/style-guide/welcome/) and the [Contributor Guide](https://learn.microsoft.com/contribute/) before making any changes.
10
+
11
+
> **Warning**
12
+
> **Do not** modify any YML files in the `python/docs-ref-autogen` folder - those are generated automatically from the library source code and any changes will be automatically overwritten the next time the documentation Continuous Integration (CI) job runs. To make changes to any API docs you will need to open a pull request in the [AzureAD/microsoft-authentication-library-for-python](https://github.com/AzureAD/microsoft-authentication-library-for-python) repository.
13
+
14
+
If you would like to author an entirely new document (e.g., for a new scenario), make sure to [open an issue](https://github.com/MicrosoftDocs/microsoft-authentication-library-for-python/issues) first. This will allow the engineering team to discuss the proposed changes and ensure that it won't be overwritten by future changes.
15
+
16
+
## API reference documentation automation
17
+
18
+
Continuous Integration (CI) jobs for this repository are available in the [automation Azure DevOps instance](https://apidrop.visualstudio.com/Content%20CI/_build?definitionId=5247).
19
+
20
+
>**Note**
21
+
>The changes from the CI job will always be pushed to the `smoke-test` branch first. To propagate them to production, merge the changes into `main`, and then merge `main` to `live`. Ensure that all checks pass before merging changes.
22
+
1
23
## Microsoft Open Source Code of Conduct
24
+
2
25
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
3
-
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
26
+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
Copy file name to clipboardExpand all lines: msal-python-conceptual/getting-started/acquiring-tokens.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,33 +5,34 @@ description: "There are many ways of acquiring a token. Some require user intera
5
5
6
6
# Acquiring tokens
7
7
8
-
As explained in [scenarios](./scenarios.md), there are many ways of acquiring a token. Some require user interaction through a web browser. Some don't require any user interaction.
9
-
In general the way to acquire a token is different depending on the application type- public client application (Desktop / Mobile) or a confidential client application (Web App, Web API, daemon application like a windows service)
8
+
As explained in [MSAL Python usage scenarios](../index.md#usage-scenarios), there are many ways of acquiring a token. Some require user interaction through a web browser, while others don't require any user interaction at all.
10
9
11
10
## Prerequisites
12
11
13
-
Before acquiring tokens with MSAL Python:
14
-
15
-
- Instantiate a [client application](./client-applications.md)
12
+
Before acquiring tokens with MSAL Python, make sure to instantiate a [client application](./client-applications.md)
16
13
17
14
## Token acquisition methods
18
15
19
-
Follow the topics below for detailed explanation with MSAL Python code usage for each token acquisition method.
16
+
The approach to acquiring a token is different depending on the application type - public client applications (desktop and mobile) or confidential client application (web app, web API, or a daemon application like a Windows service). Each of the individual approaches is described below.
20
17
21
18
### Public client applications
22
19
23
-
- Acquire tokens by [authorization code](/azure/active-directory/develop/scenario-desktop-acquire-token?tabs=python#acquiring-a-token-interactively) after letting the user sign-in through the authorization request URL.
20
+
Public client applications cannot securely store a secret and can _only_ authenticate the user that is interacting with the product. MSAL Python exposes most of the token acquisition logic for public applications through [`PublicClientApplication`](xref:msal.application.PublicClientApplication). Using this class enables developers to:
21
+
22
+
- Acquire tokens **as the user** with the help of an [interactive flow](/azure/active-directory/develop/scenario-desktop-acquire-token?tabs=python#acquiring-a-token-interactively) after letting the user sign-in through the authorization request URL.
24
23
- It's also possible (but not recommended) to get a token with a [username and password](/azure/active-directory/develop/scenario-desktop-acquire-token?tabs=python#username--password).
25
-
-Finally, for applications running on devices which don't have a web browser, it's possible to acquire a token through the [device code flow](/azure/active-directory/develop/scenario-desktop-acquire-token?tabs=python#command-line-tool-without-web-browser), which provides the user with a URL and a code. The user goes to a web browser on another device, enters the code and signs-in, and then Azure AD returns back a token to the browser-less device.
24
+
-For applications running on devices which don't have a web browser, it's possible to acquire a token through the [device code flow](/azure/active-directory/develop/scenario-desktop-acquire-token?tabs=python#command-line-tool-without-web-browser), which provides the user with a URL and a code. The user goes to a web browser on another device, enters the code and signs in. On successful authentication, Azure AD will return a token to the browser-less device.
26
25
27
26
### Confidential client applications
28
27
29
-
- Acquire token **as the application itself** using [client credentials](/azure/active-directory/develop/scenario-daemon-acquire-token?tabs=python#acquiretokenforclient-api), and not for a user. For example, in apps which process users in batches and not a particular user such as in syncing tools.
30
-
- In the case of Web Apps or Web APIs **calling another downstream Web API in the name of the user**, use the [On Behalf Of flow](/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow) to acquire a token based on some User assertion (SAML for instance, or a JWT token).
31
-
-**For Web apps in the name of a user**, acquire tokens by [authorization code](/azure/active-directory/develop/scenario-web-app-call-api-acquire-token?tabs=python) after letting the user sign-in through the authorization request URL. This is typically the mechanism used by an application which lets the user sign-in using Open ID Connect, but then wants to access Web APIs for this particular user.
28
+
Confidential client applications can securely store a secret and can authenticate both on behalf of an application as well as on behalf of a given user. With MSAL Python, developers can use [`ConfidentialClientApplication`](xref:msal.application.ConfidentialClientApplication) to access confidential client application capabilities, such as:
29
+
30
+
- Acquire token **as the application itself** using [client credentials](/azure/active-directory/develop/scenario-daemon-acquire-token?tabs=python#acquiretokenforclient-api), and not for a user. For example, this can be used in applications which process users in batches and not one particular user, such as syncing tools.
31
+
- In the case of web Apps or web APIs **calling another downstream Web API in the name of the user**, use the [On Behalf Of flow](/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow) to acquire a token based on a user assertion (e.g., SAML, JWT).
32
+
-**For Web apps authenticating in the name of a user**, acquire tokens through [authorization code](/azure/active-directory/develop/scenario-web-app-call-api-acquire-token?tabs=python) after letting the user sign-in through the authorization request URL. This is typically the mechanism used by an application which lets the user sign-in using Open ID Connect but then wants to access Web APIs for this particular user.
32
33
33
-
## MSAL Python caches tokens
34
+
## MSAL Python token caching
34
35
35
-
For both Public client and Confidential client applications, MSAL maintains a token cache, and applications should try to get a token from the cache first before any other means. Take a look at the [recommended pattern](/azure/active-directory/develop/scenario-desktop-acquire-token?tabs=python)for token acquisition.
36
+
Both public and confidential client applications support token caching, handled direclt by MSAL Python. Applications should try to get a token from the cache first before relying on any other means. Take a look at the [recommended token acquisition pattern](/azure/active-directory/develop/scenario-desktop-acquire-token?tabs=python)to learn more.
36
37
37
-
To be able to make use of the cache, the application needs to customize the [token cache serialization](/azure/active-directory/develop/msal-python-token-cache-serialization).
38
+
To be able to persist the cache, the developers will need to configure the [token cache serialization](/azure/active-directory/develop/msal-python-token-cache-serialization) logic.
Copy file name to clipboardExpand all lines: msal-python-conceptual/getting-started/client-applications.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,29 +11,33 @@ description: "How to instantiate client applications in MSAL Python."
11
11
12
12
Before instantiating your app with MSAL Python:
13
13
14
-
1. Understand the types of Client applications available- [Public Client and Confidential Client applications](/azure/active-directory/develop/msal-client-applications).
15
-
1. You'll need to [register](/azure/active-directory/develop/quickstart-register-app)the application with Azure AD. You will therefore know:
16
-
-Its `client_id`(a string representing a GUID)
17
-
- The identity provider URL (named the instance) and the sign-in audience for your application. These two parameters are collectively known as the authority.
18
-
-Possibly the `Tenant+id` in the case you are writing a line of business application (just for your organization, also named single-tenant application)
19
-
-In case it's a confidential client app, its application secret (`client_secret`string) or certificate
20
-
- For web apps, you'll have also set the `redirect_uri` where the identity provider will contact back your application with the security tokens.
14
+
1. Understand the types of client applications available- [Public Client and Confidential Client applications](/azure/active-directory/develop/msal-client-applications).
15
+
1. You'll need to [register the application](/azure/active-directory/develop/quickstart-register-app) with Azure AD. From the registration page, you will need:
16
+
-The application client identifier (a string in the form of a GUID)
17
+
- The identity provider URL (the instance) and the sign-in audience for your application. These two parameters are collectively known as the **authority**.
18
+
-If necessary, the tenant identifier (also a GUID) in case you are writing a line of business application scoped to just your organization (also known as a single-tenant application).
19
+
-If you are building a confidential client app, you will need to create an application secret in the form of a string or certificate.
20
+
- For web applications, you'll have also set the redirect URL that Azure AD will use to return the code.
21
21
22
22
### Instantiating a public client application
23
23
24
+
Public client applications use the [`PublicClientApplication`](xref:msal.application.PublicClientApplication) class.
25
+
24
26
```python
25
27
app = msal.PublicClientApplication(
26
-
config["client_id"],
27
-
authority=config["authority"],
28
+
"client_id",
29
+
authority="authority",
28
30
)
29
31
```
30
32
31
33
### Instantiating a confidential client application
32
34
35
+
Confidential client applications use the [`ConfidentialClientApplication`](xref:msal.application.ConfidentialClientApplication) class.
0 commit comments