Azure-Samples / active-directory-aspnetcore-webapp-openidconnect-v2

An ASP.NET Core Web App which lets sign-in users (including in your org, many orgs, orgs + personal accounts, sovereign clouds) and call Web APIs (including Microsoft Graph)
MIT License
1.38k stars 995 forks source link

Does Microsoft.Identity.Web work with ASP.NET Core 3.0? #191

Closed FreeSMIME closed 4 years ago

FreeSMIME commented 5 years ago

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [x ] documentation issue or request
- [x ] regression (a behavior that used to work and stopped in a new release)

The issue was found for the following scenario:

I am using Razor Pages and need to get the client authentication working and the following doesn't seem to log any middleware events

        services.AddMicrosoftIdentityPlatformAuthentication(Configuration, "AzureAd", subscribeToOpenIdConnectMiddlewareDiagnosticsEvents:true)
           .AddMsal(Configuration, new string[] { Constants.ScopeUserRead })
           .AddInMemoryTokenCaches();

It seems that I need to call TokenAcquisition.AddAccountToCacheFromAuthorizationCodeAsync(...

   var result = await application
                .AcquireTokenByAuthorizationCode(scopes.Except(_scopesRequestedByMsalNet), context.ProtocolMessage.Code)
                .ExecuteAsync()
                .ConfigureAwait(false);

... in order to populate the MSAL cache to it can be used with the OBO flow. But until then, I'm stuck.

Any suggestions on how to proceed with making Microsoft.Identity.Web work with Core 3?

(I wasn't sure what kind of project to use with Core 3, so I just dragged the files into the WebApp under the infrastructure directory. Better suggestions appreciated too. TY

TiagoBrenck commented 5 years ago

Hi @FreeSMIME, I am sorry about your troubles.

You are right on your statement about calling TokenAcquisition.AddAccountToCacheFromAuthorizationCodeAsync(...) in order to populate the token cache. This is the entry point for the caching logic.

About the ASP.NET Core 3.0 problem, I think @jmprieur will be the best person to help you.

jmprieur commented 5 years ago

@FreeSMIME : It's on the backlog to update the samples (and also MSAL.NET, BTW) to .NET Core 3.0.

Beachj commented 5 years ago

Any idea on when these will be migrated to 3.0?

jmprieur commented 5 years ago

We are working on it For the ASP.NET Core Web API tutorial, we already have a PR. https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/pull/111 I hope to get to this for the ASP.NET Core Web app today and the .NET daemon core daemon app calling its own Web API today (will be the same code for Microsoft.Identity.Web btw)

jasonshave commented 4 years ago

@jmprieur looks like the PR was merged. Is it safe to say the current build works with .NET Core 3.0?

jmprieur commented 4 years ago

@jasonshave : the ASP.NET Core Web API tutorial (for which the PR got merged) is ready. The ASP.NET Core Web app needs a bit more work. On it (intermittently as I also have other things to do)

jmprieur commented 4 years ago

Done