Azure Application Proxy access using MSAL token
See original GitHub issueImplemented test windows application based on official manual: https://docs.microsoft.com/en-us/azure/active-directory/manage-apps/application-proxy-configure-native-client-application
Following code is a result:
IPublicClientApplication clientApp = PublicClientApplicationBuilder
.Create("Native App Client Id")
.WithRedirectUri("http://localhost")
.WithAuthority("https://login.microsoftonline.com/"My Tenant ID"")
.Build();
Microsoft.Identity.Client.AuthenticationResult authResult = null;
var accounts = await clientApp.GetAccountsAsync();
IAccount account = accounts.FirstOrDefault();
IEnumerable<string> scopes = new string[] { "api://"APP Proxy Uri"/user_impersonation" };
try
{
authResult = await clientApp.AcquireTokenSilent(scopes, account).ExecuteAsync();
}
catch (MsalUiRequiredException ex)
{
authResult = await clientApp.AcquireTokenInteractive(scopes).ExecuteAsync();
}
if (authResult != null)
{
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
HttpResponseMessage response = await httpClient.GetAsync("App Proxy based URL"+ "/api/values");
Everything works fine until HTTP request with a token, it is being redirected to login.microsoft.com: https://i.stack.imgur.com/GUe7l.png
Any ideas what’s wrong? Browser access works just fine, also JWT token is fully valid and being passed correctly.
Issue Analytics
- State:
- Created 3 years ago
- Comments:24 (10 by maintainers)
Top Results From Across the Web
Access on-premises APIs with Azure Active Directory ...
Azure AD Application Proxy and the Microsoft Authentication Library (MSAL) let your native apps securely access your on-premises APIs.
Read more >Azure App Proxy and SPA application using MSAL causes ...
I'm trying to access a SPA application using MSAL authentication with Azure AD. For this we have created a App Registration in Azure....
Read more >REST API http requests to internal app through Azure ...
To get through the Azure App Proxy I'm using MSAL to get my Azure AD Access Token and supplying that token via the...
Read more >Azure AD Application Proxy: Workflow and Best Practices
Azure Active Directory (AD) offers an Application Proxy feature that lets you access on-prem web applications using a remote client.
Read more >Azure AD Application proxy and some previews
This Application Proxy service runs in the cloud as part of Azure AD. It passes the sign-on token from the user to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unfortunately, the MS ticket solved my issue. My work was a POC so I didn’t progress any further.
— Chuck On Nov 1, 2021, 4:05 AM -0700, Nasir @.***>, wrote:
I did, I opened up a ticket with Microsoft and they helped me.
I updated my answer on Stackoverflow: https://stackoverflow.com/questions/66975070/accessing-on-premise-api-through-azure-proxy-with-azure-directory-enabled
I hope that helps.
— Chuck On Nov 1, 2021, 2:53 AM -0700, Nasir @.***>, wrote: