3
votes

Given an azure function secured via AAD B2C with https://login.microsoftonline.com/tfp/MyTenantName.onmicrosoft.com/signinsingunp as issuer url, I can successfully authenticate a b2c user via msal.js app, where as if I try to update issuer url to my b2ctenant domain login url (because of this advise redirect URLs to b2clogin.com) and update authority in msal.js app to match domain(myapp.b2clogin.com/tfp/MyTenantName.onmicrosoft.com/signinsingunp), I am receiving 401 for same azure function, any advise will be appreciated.

Below are detailed setup details,

Thanks in advance!

2
What kind of account you are using for? - Md Farid Uddin Kiron
@MdFaridUddinKiron : Sorry, I can't understand your question. Can you pls elaborate. - ManiVI
Sure,I asked you what kind of user email you have used there as there are personal and work email and its mattered in b2c account. - Md Farid Uddin Kiron
as a test user, its an personal gmail account. At the moment in azure b2c tenant user flow policies > mysignupsignin-identity providers > Local Account Email sign up is enabled. - ManiVI
official sample outlines how to setup/consume msal.js For some reason, the changes/updates are not immediate, it took me ~6-8 hours to work correctly ! - ManiVI

2 Answers

2
votes

I've finally found a solution to this...

It took a lot of scouring but it's down to this issue raised on GitHub

Essentially, I changed the authority when setting up my UserAgentApplication to use the new b2clogin.com domain that someone else mentioned. Although this didn't work immediately, I received the same error you mentioned in the comments, so I had to set validateAuthority: false on my config.

I've included an example below on how I've set mine up. My ClientID is the same in Azure as it is in MSAL.js

var msalConfig = {
      auth: {
        clientId: "xxxx",
        authority: "https://xxxx.b2clogin.com/tfp/xxxx.onmicrosoft.com/B2C_xxxx", 
        webApi: 'https://xxxx.azurewebsites.net',
        b2cScopes: this.appConfig.b2cScopes,
        validateAuthority: false
      },
      cache: {
        cacheLocation: "localStorage",
        storeAuthStateInCookie: true
      }
    };
this.clientApplication = new Msal.UserAgentApplication(msalConfig);

Hope this helps!

0
votes

All you need to do is changing Issuer URL (you wrote as Issuer URL but that must be .well-known config URL) to match with b2clogin.com domain.

From above I see your OpenID config URL at Azure functions is

login.microsoftonline.com/......./opendid......

But It should match with .well-known configuration of the static website of your b2clogin domain. It should be like

https://tenantname.b2clogin.com/tfp/tenantname.onmicrosoft.com/B2C_1_Policy/v2.0/.well-known/openid-configuration