Azure-Samples/active-directory-b2c-dotnetcore-webapp

Sample works in 1.1 branch but not 2.0 branch (null MSAL token)

Marren85 opened this issue · 11 comments

The sample works perfectly in core 1.1 but in the 2.0 branch it doesn't.

The

public async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedContext context)

is never hit.

All I've been trying for the last year is to get a stupid token with MSAL. I thought we were close here.

How on earth can I get an MSAL token for my B2C API in .net core 2.0?

I've downloaded the sample....doesn't work
Recreated from scratch adding the response type as code id_token to hit the AuthResponse...token is null

WHY IS IT NULL!!

What is that has changed between 1.1 and 2.0 that makes the access token null?

It will something so simple and for the life of me I can't see it...

Readded the variables to the 1.1 sample and works perfectly first time...why not in 2.0?

Hi chaimzf, I did use the 2.0 branch. As I said in the first post, it doesnt work.

The 1.1 branch works perfectly.
The 2.0 branch does not.

AuthcodeRecv is never hit in the 2.0 branch,

2.0 branch needs adjusting to have a requesttype of code id_token to hit the AuthCodeRecv.

Within the 2.0 branch AuthCodeRecv event, in the MSAL request respone, the token is always null...

I've spent so much time on this, its not even funny!

So, I went back to the 1.1 branch, which we know works..I manually upgraded to 2.0 so a lot of the code stays the same (which we know works)...Tested...null token.

To play safe, I completely removed the AzureB2CExtensions and added the bare minimum to Startup to make Azure B2C work with OpenIDConnect and used the 1.1 branch OnAuthCodeRecv which we know works...null token.

probably this doesn't give you much help but I can confirm that it was the other way round for me. 1.1 branch didnt' work, 2.0 branch works just fine, i can log in using social provider, log out etc. With zero changes to source code.

Hi @jg11jg the logging in is a separate concern, ironically that works in both 1.1 and 2.0 branches, the MSAL token is a separate request which doesn't effect the logging in process.

I just cant believe after all this time, this still doesn't work, I've been following this for over a year

@Marren85 When you say "MSAL token", are you referring to an access token?

Could you send me the request that you are making? Fiddler or Chrome might be useful to capture it, or you can set up a debugger.

The scope that is being sent is likely incorrect, so just want to confirm.

@parakhj its the exact same scope that successfully generates a token in the 1.1 branch, its just for an API with a published scope in my B2C tenant.

If there was a problem with the scope, it wouldn't get the token in the 1.1 branch surely?

1.1 Branch
1-1 branch

2.0 Branch
2-0 branch

Your caching issue is interesting I'm going to delete everything and recreate

Fixed It!

How you may ask...I have no idea but I will run through the steps for anyone else having the same problem...

All in Azure...firstly delete your WebApp and API from the Applications in the B2C blade.

Recreate the WebApp and API, remembering to add Published Scopes to the API and API Access to the WebApp, you can use the same scopes from the code you already have.

In your code you will need to update the variables which have changed (ClientID, Secret)

That's it, for whatever reason it works! Whatever the problem was it was on the Azure end and I have no idea what that might be!

So to sum up, I've ended up with the same Azure settings I had before, the same code I had before but now it works!

Seen as you've already updates the code to add the ResponseType to hit the AuthCodeRecv like I said, this can be closed!