Skip to content

Commit fd77aca

Browse files
authored
Merge pull request #115028 from msmimart/mm-msalupdate
[App Proxy] MSAL updates (replaces PR 53645)
2 parents 66c3013 + 9b7645e commit fd77aca

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

articles/active-directory/manage-apps/application-proxy-configure-native-client-application.md

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ ms.workload: identity
1212
ms.tgt_pltfrm: na
1313
ms.devlang: na
1414
ms.topic: conceptual
15-
ms.date: 04/15/2019
15+
ms.date: 05/12/2020
1616
ms.author: mimart
1717
ms.reviewer: japere
18-
ms.custom: it-pro, has-adal-ref
18+
ms.custom: it-pro
1919

2020
ms.collection: M365-identity-device-management
2121
---
2222

2323
# How to enable native client applications to interact with proxy applications
2424

25-
You can use Azure Active Directory (Azure AD) Application Proxy to publish web apps, but it also can be used to publish native client applications that are configured with the Azure AD Authentication Library (ADAL). Native client applications differ from web apps because they're installed on a device, while web apps are accessed through a browser.
25+
You can use Azure Active Directory (Azure AD) Application Proxy to publish web apps, but it also can be used to publish native client applications that are configured with the Microsoft Authentication Library (MSAL). Native client applications differ from web apps because they're installed on a device, while web apps are accessed through a browser.
2626

2727
To support native client applications, Application Proxy accepts Azure AD-issued tokens that are sent in the header. The Application Proxy service does the authentication for the users. This solution doesn't use application tokens for authentication.
2828

2929
![Relationship between end users, Azure AD, and published applications](./media/application-proxy-configure-native-client-application/richclientflow.png)
3030

31-
To publish native applications, use the Azure AD Authentication Library, which takes care of authentication and supports many client environments. Application Proxy fits into the [Native Application to Web API scenario](../azuread-dev/native-app.md).
31+
To publish native applications, use the Microsoft Authentication Library, which takes care of authentication and supports many client environments. Application Proxy fits into the [Desktop app that calls a web API on behalf of a signed-in user](https://docs.microsoft.com/azure/active-directory/develop/authentication-flows-app-scenarios#desktop-app-that-calls-a-web-api-on-behalf-of-a-signed-in-user) scenario.
3232

3333
This article walks you through the four steps to publish a native application with Application Proxy and the Azure AD Authentication Library.
3434

@@ -53,8 +53,7 @@ You now need to register your application in Azure AD, as follows:
5353
- To target only accounts that are internal to your organization, select **Accounts in this organizational directory only**.
5454
- To target only business or educational customers, select **Accounts in any organizational directory**.
5555
- To target the widest set of Microsoft identities, select **Accounts in any organizational directory and personal Microsoft accounts**.
56-
57-
1. In the **Redirect URI** heading, select **Public client (mobile & desktop)**, and then type the redirect URI for your application.
56+
1. Under **Redirect URI**, select **Public client (mobile & desktop)**, and then type the redirect URI `https://login.microsoftonline.com/common/oauth2/nativeclient` for your application.
5857
1. Select and read the **Microsoft Platform Policies**, and then select **Register**. An overview page for the new application registration is created and displayed.
5958

6059
For more detailed information about creating a new application registration, see [Integrating applications with Azure Active Directory](../develop/quickstart-register-app.md).
@@ -66,42 +65,60 @@ Now that you've registered your native application, you can give it access to ot
6665
1. In the sidebar of the new application registration page, select **API permissions**. The **API permissions** page for the new application registration appears.
6766
1. Select **Add a permission**. The **Request API permissions** page appears.
6867
1. Under the **Select an API** setting, select **APIs my organization uses**. A list appears, containing the applications in your directory that expose APIs.
69-
1. Type in the search box or scroll to find the proxy application that you published in [Step 1: Publish your proxy application](#step-1-publish-your-proxy-application), and then select the proxy application.
68+
1. Type in the search box or scroll to find the proxy application that you published in [Step 1: Publish your proxy application](https://docs.microsoft.com/azure/active-directory/manage-apps/application-proxy-configure-native-client-application#step-1-publish-your-proxy-application), and then select the proxy application.
7069
1. In the **What type of permissions does your application require?** heading, select the permission type. If your native application needs to access the proxy application API as the signed-in user, choose **Delegated permissions**.
7170
1. In the **Select permissions** heading, select the desired permission, and select **Add permissions**. The **API permissions** page for your native application now shows the proxy application and permission API that you added.
7271

73-
## Step 4: Edit the Active Directory Authentication Library
72+
## Step 4: Add the Microsoft Authentication Library to your code (.NET C# sample)
7473

75-
Edit the native application code in the authentication context of the Active Directory Authentication Library (ADAL) to include the following text:
74+
Edit the native application code in the authentication context of the Microsoft Authentication Library (MSAL) to include the following text:
7675

77-
```
76+
```
7877
// Acquire Access Token from AAD for Proxy Application
79-
AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/<Tenant ID>");
80-
AuthenticationResult result = await authContext.AcquireTokenAsync("< External Url of Proxy App >",
81-
"<App ID of the Native app>",
82-
new Uri("<Redirect Uri of the Native App>"),
83-
PromptBehavior.Never);
84-
85-
//Use the Access Token to access the Proxy Application
86-
HttpClient httpClient = new HttpClient();
87-
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
88-
HttpResponseMessage response = await httpClient.GetAsync("< Proxy App API Url >");
78+
IPublicClientApplication clientApp = PublicClientApplicationBuilder
79+
.Create(<App ID of the Native app>)
80+
.WithDefaultRedirectUri() // will automatically use the default Uri for native app
81+
.WithAuthority("https://login.microsoftonline.com/{<Tenant ID>}")
82+
.Build();
83+
84+
AuthenticationResult authResult = null;
85+
var accounts = await clientApp.GetAccountsAsync();
86+
IAccount account = accounts.FirstOrDefault();
87+
88+
IEnumerable<string> scopes = new string[] {"<Scope>"};
89+
90+
try
91+
{
92+
authResult = await clientApp.AcquireTokenSilent(scopes, account).ExecuteAsync();
93+
}
94+
catch (MsalUiRequiredException ex)
95+
{
96+
authResult = await clientApp.AcquireTokenInteractive(scopes).ExecuteAsync();
97+
}
98+
99+
if (authResult != null)
100+
{
101+
//Use the Access Token to access the Proxy Application
102+
103+
HttpClient httpClient = new HttpClient();
104+
HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
105+
HttpResponseMessage response = await httpClient.GetAsync("<Proxy App Url>");
106+
}
89107
```
90108

91109
The required info in the sample code can be found in the Azure AD portal, as follows:
92110

93111
| Info required | How to find it in the Azure AD portal |
94112
| --- | --- |
95113
| \<Tenant ID> | **Azure Active Directory** > **Properties** > **Directory ID** |
96-
| \<External Url of Proxy App> | **Enterprise applications** > *your proxy application* > **Application proxy** > **External Url** |
97-
| \<App ID of the Native app> | **Enterprise applications** > *your native application* > **Properties** > **Application ID** |
98-
| \<Redirect URI of the Native App> | **Azure Active Directory** > **App registrations** > *your native application* > **Redirect URIs** |
99-
| \<Proxy App API Url> | **Azure Active Directory** > **App registrations** > *your native application* > **API permissions** > **API / PERMISSIONS NAME** |
114+
| \<App ID of the Native app> | **Application registration** > *your native application* > **Overview** > **Application ID** |
115+
| \<Scope> | **Application registration** > *your native application* > **API permissions** > Click on the Permission API (user_impersonation) > A panel with the caption **user_impersonation** appears on the right hand side. > The scope is the URL in the edit box.
116+
| \<Proxy App Url> | the External Url and path to the API
100117

101-
After you edit the ADAL with these parameters, your users can authenticate to native client applications even when they're outside of the corporate network.
118+
After you edit the MSAL code with these parameters, your users can authenticate to native client applications even when they are outside of the corporate network.
102119

103120
## Next steps
104121

105122
For more information about the native application flow, see [Native apps in Azure Active Directory](../azuread-dev/native-app.md).
106123

107-
Learn about setting up [Single sign-on to applications in Azure Active Directory](what-is-single-sign-on.md#choosing-a-single-sign-on-method).
124+
Learn about setting up [Single sign-on to applications in Azure Active Directory](what-is-single-sign-on.md#choosing-a-single-sign-on-method).

0 commit comments

Comments
 (0)