Skip to content

Commit c0b2110

Browse files
authored
Merge pull request #96876 from TylerMSFT/twhitney-PythonPorting
Twhitney python porting
2 parents 99d436b + 00c4d2a commit c0b2110

8 files changed

+368
-278
lines changed

articles/active-directory/develop/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
- name: .NET Core console (daemon)
6161
href: quickstart-v2-netcore-daemon.md
6262
- name: Python console daemon
63-
href: quickstart-v2-python-daemon.md
63+
href: quickstart-v2-python-daemon.md
6464
- name: Tutorials
6565
items:
6666
- name: Single-page apps
@@ -289,6 +289,8 @@
289289
items:
290290
- name: ADFS support in MSAL.NET
291291
href: msal-net-adfs-support.md
292+
- name: ADFS support in MSAL for Python
293+
href: msal-python-adfs-support.md
292294
- name: ADFS support in MSAL for Java
293295
href: msal-java-adfs-support.md
294296
- name: Integrate with Azure AD B2C

articles/active-directory/develop/migrate-python-adal-msal.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ADAL Python acquires tokens for resources, but MSAL Python acquires tokens for s
4646

4747
### Error handling
4848

49-
Azure Active Directory Authentication Library (ADAL) for Python uses the exception `AdalError` to indicate that there's been a problem. MSAL for Python typically uses error codes, instead. For more information, see [MSAL for Python error handling](msal-handling-exceptions.md#msal-for-python-error-handling).
49+
Azure Active Directory Authentication Library (ADAL) for Python uses the exception `AdalError` to indicate that there's been a problem. MSAL for Python typically uses error codes, instead. For more information, see [MSAL for Python error handling](https://docs.microsoft.com/azure/active-directory/develop/msal-handling-exceptions?tabs=python).
5050

5151
### API changes
5252

@@ -58,7 +58,7 @@ The following table lists an API in ADAL for Python, and the one to use in its p
5858
| N/A | [get_authorization_request_url()](https://msal-python.readthedocs.io/en/latest/#msal.ClientApplication.get_authorization_request_url) |
5959
| [acquire_token_with_authorization_code()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.acquire_token_with_authorization_code) | [acquire_token_by_authorization_code()](https://msal-python.readthedocs.io/en/latest/#msal.ClientApplication.acquire_token_by_authorization_code) |
6060
| [acquire_token()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.acquire_token) | [acquire_token_silent()](https://msal-python.readthedocs.io/en/latest/#msal.ClientApplication.acquire_token_silent) |
61-
| [acquire_token_with_refresh_token()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.acquire_token_with_refresh_token) | N/A (See the section above) |
61+
| [acquire_token_with_refresh_token()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.acquire_token_with_refresh_token) | N/A |
6262
| [acquire_user_code()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.acquire_user_code) | [initiate_device_flow()](https://msal-python.readthedocs.io/en/latest/#msal.PublicClientApplication.initiate_device_flow) |
6363
| [acquire_token_with_device_code()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.acquire_token_with_device_code) and [cancel_request_to_get_token_with_device_code()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.cancel_request_to_get_token_with_device_code) | [acquire_token_by_device_flow()](https://msal-python.readthedocs.io/en/latest/#msal.PublicClientApplication.acquire_token_by_device_flow) |
6464
| [acquire_token_with_username_password()](https://adal-python.readthedocs.io/en/latest/#adal.AuthenticationContext.acquire_token_with_username_password) | [acquire_token_by_username_password()](https://msal-python.readthedocs.io/en/latest/#msal.PublicClientApplication.acquire_token_by_username_password) |

articles/active-directory/develop/msal-handling-exceptions.md

Lines changed: 242 additions & 257 deletions
Large diffs are not rendered by default.

articles/active-directory/develop/msal-java-adfs-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ The supported AD FS versions in this federated scenario are:
4848

4949
When you acquire a token using `ConfidentialClientApplication.AcquireToken()` or `PublicClientApplication.AcquireToken()` with `IntegratedWindowsAuthenticationParameters` or `UsernamePasswordParameters`, MSAL for Java gets the identity provider to contact based on the username. MSAL for Java gets a [SAML 1.1 token](reference-saml-tokens.md) token from the identity provider, which it then provides to Azure AD which returns the JSON Web Token (JWT).
5050

51-
## See also
51+
## Next steps
5252

5353
For the federated case, see [Configure Azure Active Directory sign in behavior for an application by using a Home Realm Discovery policy](https://docs.microsoft.com/azure/active-directory/manage-apps/configure-authentication-for-federated-users-portal)

articles/active-directory/develop/msal-national-cloud.md

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,18 @@ If you don't have an Azure Government subscription, create a [free account](http
5656

5757
For details about using a national cloud with a particular programming language, choose the tab matching your language:
5858

59+
## [.NET](#tab/donet)
60+
61+
You can use MSAL.NET to sign in users, acquire tokens, and call the Microsoft Graph API in national clouds.
62+
63+
The following tutorials demonstrate how to build a .NET Core 2.2 MVC Web app. The app uses OpenID Connect to sign in users with a work and school account in an organization that belongs to a national cloud.
64+
65+
- To sign in users and acquire tokens, follow this tutorial: [Build an ASP.NET Core Web app signing-in users in sovereign clouds with the Microsoft identity platform](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-4-Sovereign#build-an-aspnet-core-web-app-signing-in-users-in-sovereign-clouds-with-the-microsoft-identity-platform).
66+
- To call the Microsoft Graph API, follow this tutorial: [Using the Microsoft identity platform to call the Microsoft Graph API from an An ASP.NET Core 2.x Web App, on behalf of a user signing-in using their work and school account in Microsoft National Cloud](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/2-WebApp-graph-user/2-4-Sovereign-Call-MSGraph#using-the-microsoft-identity-platform-to-call-the-microsoft-graph-api-from-an-an-aspnet-core-2x-web-app-on-behalf-of-a-user-signing-in-using-their-work-and-school-account-in-microsoft-national-cloud).
67+
5968
## [JavaScript](#tab/javascript)
6069

61-
## JavaScript
70+
To enable your MSAL.js application for sovereign clouds:
6271

6372
### Step 1: Register your application
6473

@@ -128,17 +137,53 @@ In that code:
128137

129138
To find Microsoft Graph endpoints for all the national clouds, see [Microsoft Graph endpoints in national clouds](https://docs.microsoft.com/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints).
130139

131-
## .NET
140+
## [Python](#tab/python)
132141

133-
You can use MSAL.NET to sign in users, acquire tokens, and call the Microsoft Graph API in national clouds.
142+
To enable your MSAL Python application for sovereign clouds:
134143

135-
The following tutorials demonstrate how to build a .NET Core 2.2 MVC Web app. The app uses OpenID Connect to sign in users with a work and school account in an organization that belongs to a national cloud.
144+
- Register your application in a specific portal, depending on the cloud. For more information on how to choose the portal refer [App registration endpoints](authentication-national-cloud.md#app-registration-endpoints)
145+
- Use any of the [samples](https://github.com/AzureAD/microsoft-authentication-library-for-python/tree/dev/sample) from the repo with a few changes to the configuration, depending on the cloud, which is mentioned next.
146+
- Use a specific authority, depending on the cloud you registered the application in. For more information on authorities for different clouds, refer [Azure AD Authentication endpoints](authentication-national-cloud.md#azure-ad-authentication-endpoints).
147+
148+
Here's an example authority:
149+
150+
```json
151+
"authority": "https://login.microsoftonline.us/Enter_the_Tenant_Info_Here"
152+
```
153+
154+
- To call Microsoft graph requires a specific Graph endpoint URL that depends on which cloud you are using. To find Microsoft Graph endpoints for all the national clouds, refer to [Microsoft Graph and Graph Explorer service root endpoints](https://docs.microsoft.com/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints).
155+
156+
Here's an example of a graph endpoint, with scope:
157+
158+
```json
159+
"endpoint" : "https://graph.microsoft.us/v1.0/me"
160+
"scope": "User.Read"
161+
```
162+
163+
## [Java](#tab/java)
136164

137-
- To sign in users and acquire tokens, follow [this tutorial](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-4-Sovereign#build-an-aspnet-core-web-app-signing-in-users-in-sovereign-clouds-with-the-microsoft-identity-platform).
138-
- To call the Microsoft Graph API, follow [this tutorial](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/2-WebApp-graph-user/2-4-Sovereign-Call-MSGraph#using-the-microsoft-identity-platform-to-call-the-microsoft-graph-api-from-an-an-aspnet-core-2x-web-app-on-behalf-of-a-user-signing-in-using-their-work-and-school-account-in-microsoft-national-cloud).
165+
To enable your MSAL for Java application for sovereign clouds:
166+
167+
- Register your application in a specific portal, depending on the cloud. For more information on how to choose the portal refer [App registration endpoints](authentication-national-cloud.md#app-registration-endpoints)
168+
- Use any of the [samples](https://github.com/AzureAD/microsoft-authentication-library-for-java/tree/dev/src/samples) from the repo with a few changes to the configuration, depending on the cloud, which are mentioned next.
169+
- Use a specific authority, depending on the cloud you registered the application in. For more information on authorities for different clouds, refer [Azure AD Authentication endpoints](authentication-national-cloud.md#azure-ad-authentication-endpoints).
170+
171+
Here's an example authority:
172+
173+
```json
174+
"authority": "https://login.microsoftonline.us/Enter_the_Tenant_Info_Here"
175+
```
176+
177+
- To call Microsoft graph requires a specific Graph endpoint URL that depends on which cloud you are using. To find Microsoft Graph endpoints for all the national clouds, refer to [Microsoft Graph and Graph Explorer service root endpoints](https://docs.microsoft.com/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints).
178+
179+
Here's an example of a graph endpoint, with scope:
180+
181+
```json
182+
"endpoint" : "https://graph.microsoft.us/v1.0/me"
183+
"scope": "User.Read"
184+
```
139185

140186
## [Objective-C](#tab/objc)
141-
## MSAL for iOS and macOS
142187

143188
MSAL for iOS and macOS can be used to acquire tokens in national clouds, but it requires additional configuration when creating `MSALPublicClientApplication`.
144189

@@ -174,14 +219,6 @@ let config = MSALPublicClientApplicationConfig(clientId: "<your-client-id-here>"
174219
if let application = try? MSALPublicClientApplication(configuration: config) { /* Use application */}
175220
```
176221

177-
## [Java](#tab/java)
178-
179-
To enable your MSAL for Java application for sovereign clouds, you must:
180-
181-
- Register your application in a specific portal, depending on the cloud
182-
- Use a specific authority, depending on the cloud in the config file for your application
183-
- To call the Microsoft Graph API requires a specific Graph endpoint URL, depending on the cloud.
184-
185222
---
186223

187224
## Next steps

articles/active-directory/develop/msal-net-adfs-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ Currently, there are no plans to support a direct connection to:
5858

5959
If you need to support scenarios requiring a direct connection to AD FS 2016, use the latest version of [Azure Active Directory Authentication Library](active-directory-authentication-libraries.md#microsoft-supported-client-libraries). When you have upgraded your on-premises system to AD FS 2019, you'll be able to use MSAL.NET.
6060

61-
## See also
61+
## Next steps
6262

6363
For the federated case, see [Configure Azure Active Directory sign in behavior for an application by using a Home Realm Discovery policy](https://docs.microsoft.com/azure/active-directory/manage-apps/configure-authentication-for-federated-users-portal)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Azure AD FS support in Microsoft Authentication Library for Python
3+
titleSuffix: Microsoft identity platform
4+
description: Learn about Active Directory Federation Services (AD FS) support in Microsoft Authentication Library for Python
5+
services: active-directory
6+
documentationcenter: dev-center-name
7+
author: abhidnya13
8+
manager: henrikm
9+
editor: ''
10+
11+
ms.service: active-directory
12+
ms.subservice: develop
13+
ms.devlang: na
14+
ms.topic: conceptual
15+
ms.tgt_pltfrm: na
16+
ms.workload: identity
17+
ms.date: 11/23/2019
18+
ms.author: abpati
19+
ms.reviewer: navyasri.canumalla
20+
ms.custom: aaddev
21+
#Customer intent: As an application developer, I want to learn about AD FS support in MSAL for Python so I can decide if this platform meets my application development needs and requirements.
22+
ms.collection: M365-identity-device-management
23+
---
24+
25+
# Active Directory Federation Services support in MSAL for Python
26+
27+
Active Directory Federation Services (AD FS) in Windows Server enables you to add OpenID Connect and OAuth 2.0 based authentication and authorization to your apps by using the Microsoft Authentication Library (MSAL) for Python. Using the MSAL for Python library, your app can authenticate users directly against AD FS. For more information about scenarios, see [AD FS Scenarios for Developers](https://docs.microsoft.com/windows-server/identity/ad-fs/overview/ad-fs-scenarios-for-developers).
28+
29+
There are usually two ways of authenticating against AD FS:
30+
31+
- MSAL Python talks to Azure Active Directory, which itself is federated with other identity providers. The federation happens through AD FS. MSAL Python connects to Azure AD, which signs in users that are managed in Azure AD (managed users) or users managed by another identity provider such as AD FS (federated users). MSAL Python doesn't know that a user is federated. It simply talks to Azure AD. The [authority](msal-client-application-configuration.md#authority) you use in this case is the usual authority (authority host name + tenant, common, or organizations).
32+
- MSAL Python talks directly to an AD FS authority. This is only supported by AD FS 2019 and later.
33+
34+
## Connect to Active Directory federated with AD FS
35+
36+
### Acquire a token interactively for a federated user
37+
38+
The following applies whether you connect directly to Active Directory Federation Services (AD FS) or through Active Directory.
39+
40+
When you call `acquire_token_by_authorization_code` or `acquire_token_by_device_flow`, the user experience is typically as follows:
41+
42+
1. The user enters their account ID.
43+
2. Azure AD displays briefly the message "Taking you to your organization's page" and the user is redirected to the sign-in page of the identity provider. The sign-in page is usually customized with the logo of the organization.
44+
45+
The supported AD FS versions in this federated scenario are:
46+
- Active Directory Federation Services FS v2
47+
- Active Directory Federation Services v3 (Windows Server 2012 R2)
48+
- Active Directory Federation Services v4 (AD FS 2016)
49+
50+
### Acquire a token via username and password
51+
52+
The following applies whether you connect directly to Active Directory Federation Services (AD FS) or through Active Directory.
53+
54+
When you acquire a token using `acquire_token_by_username_password`, MSAL Python gets the identity provider to contact based on the username. MSAL Python gets a [SAML 1.1 token](reference-saml-tokens.md) from the identity provider, which it then provides to Azure AD which returns the JSON Web Token (JWT).
55+
56+
## Connecting directly to AD FS
57+
58+
When you connect directory to AD FS, the authority you'll want to use to build your application will be something like `https://somesite.contoso.com/adfs/`
59+
60+
MSAL Python supports ADFS 2019.
61+
62+
It does not support a direct connection to ADFS 2016 or ADFS v2. If you need to support scenarios requiring a direct connection to ADFS 2016, use the latest version of ADAL Python. Once you have upgraded your on-premises system to ADFS 2019, you can use MSAL Python.
63+
64+
## Next steps
65+
66+
- For the federated case, see [Configure Azure Active Directory sign in behavior for an application by using a Home Realm Discovery policy](../manage-apps/configure-authentication-for-federated-users-portal.md)

articles/active-directory/develop/scenario-web-app-sign-user-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ As a second phase, you can enable your application to call web APIs on behalf of
8383
# [ASP.NET Core](#tab/aspnetcore)
8484

8585
> [!div class="nextstepaction"]
86-
> [App registration](https://docs.microsoft.com/azure/active-directory/develop/scenario-web-app-sign-user-app-registration?tabs=aspnetcore?tabs=aspnetcore)
86+
> [App registration](https://docs.microsoft.com/azure/active-directory/develop/scenario-web-app-sign-user-app-registration?tabs=aspnetcore)
8787
8888
# [ASP.NET](#tab/aspnet)
8989

0 commit comments

Comments
 (0)