Skip to content

Commit 14b754f

Browse files
authored
Merge pull request #66 from SHERMANOUKO/client-applications
Improve client app documentation
2 parents aa62a48 + 4e941b5 commit 14b754f

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed
Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,69 @@
11
---
22
title: Client applications
33
description: "How to instantiate client applications in MSAL Python."
4-
author: Dickson-Mwendia
4+
author: SHERMANOUKO
55
manager: CelesteDG
66

77
ms.service: msal
88
ms.subservice: msal-python
99
ms.topic: conceptual
10-
ms.date: 02/07/2024
11-
ms.author: dmwendia
12-
ms.reviewer: shermanouko, rayluo
10+
ms.date: 03/07/2024
11+
ms.author: shermanouko
12+
ms.reviewer: dmwendia, rayluo
1313
---
1414

1515
# Client applications
1616

17-
## Instantiating an application
17+
Microsoft Authentication Library (MSAL) Python supports two types of client applications: public client applications and confidential client applications. The client types are distinguished by their ability to authenticate securely with the authorization server and to hold sensitive, identity proving information so that it can't be accessed or known to a user within the scope of its access. This article focuses on how to initialize these applications using MSAL Python.
1818

19-
### Prerequisites
19+
## Prerequisites
2020

21-
Before instantiating your app with MSAL Python:
21+
This article doesn't go deep into defining what a public and confidential client applications are. Visit the identity platform docs to learn more about [public and confidential client applications](/entra/identity-platform/msal-client-applications).
2222

23-
1. Understand the types of client applications available - [Public Client and Confidential Client applications](/azure/active-directory/develop/msal-client-applications).
24-
1. You'll need to [register the application](/azure/active-directory/develop/quickstart-register-app) with Microsoft Entra ID. From the registration page, you will need:
25-
- The application client identifier (a string in the form of a GUID)
26-
- The identity provider URL (the instance) and the sign-in audience for your application. These two parameters are collectively known as the **authority**.
27-
- 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).
28-
- If you are building a confidential client app, you will need to create an application secret in the form of a string or certificate.
29-
- For web applications, you'll have also set the redirect URL that Microsoft Entra ID will use to return the code. For desktop applications you will need to add `http://localhost` if you're not relying on authentication brokers.
23+
## Instantiate an application
3024

31-
### Instantiating a public client application
25+
You require an app registration to initiate an app. [Register an app](/entra/identity-platform/quickstart-register-app) in the Microsoft Entra admin center. From the registration page, you need:
26+
27+
- The application client identifieR. This is a string in the form of a GUID.
28+
- The identity provider URL (the instance) and the sign-in audience for your application. These two parameters are collectively known as the *authority*.
29+
- If necessary, the tenant identifier (also a GUID) in case you're writing a line of business application scoped to just your organization (also known as a single-tenant application).
30+
- If you're building a confidential client app, create an application secret in the form of a string or certificate.
31+
- For web applications, set the redirect URL that Microsoft Entra ID uses to return the code. For desktop applications, add `http://localhost` if you're not relying on authentication brokers.
32+
33+
## Instantiate a public client application
3234

3335
Public client applications use the [`PublicClientApplication`](xref:msal.application.PublicClientApplication) class.
3436

3537
```python
38+
import msal
39+
3640
app = msal.PublicClientApplication(
3741
"client_id",
3842
authority="authority",
3943
)
4044
```
4145

42-
### Instantiating a confidential client application
46+
## Instantiate a confidential client application
4347

4448
Confidential client applications use the [`ConfidentialClientApplication`](xref:msal.application.ConfidentialClientApplication) class.
4549

4650
```python
51+
import msal
52+
4753
app = msal.ConfidentialClientApplication(
4854
"client_id",
4955
authority="authority",
5056
client_credential="client_secret",
5157
)
5258
```
59+
60+
## Caching
61+
62+
When you instantiate a client application, there are two parameters you can use to define your caching preferences. These parameters are: `token_cache` and `http_cache`.
63+
64+
- `token_cache` sets the token cache used by the client application instance. By default, an in-memory cache is created and used. For more information, see [token caching in MSAL Python](../advanced/msal-python-token-cache-serialization.md).
65+
- `http_cache` is available in MSAL Python version 1.16+. This automatically caches some finite number of nontoken http responses, so that long-lived `PublicClientApplication` and `ConfidentialClientApplication` instances would be more performant and responsive in some situations. If the `http_cache` parameter isn't provided, MSAL uses an in-memory dict. If your app is a command-line app (CLI), you would want to persist your `http_cache` across different CLI runs. For more information, see the [reference guide](/python/api/msal/msal.application.clientapplication).
66+
67+
## Next steps
68+
69+
[Acquire tokens for your app](acquiring-tokens.md).

0 commit comments

Comments
 (0)