Search code examples
reactjsazureazure-active-directoryadal

Porting app from react-azure-adb2c to react-aad


I am using Azure AD B2C. I need some react library to authenticate users in my react.js app.

I started with react-azure-adb2c. Primary scenarios like login and logout worked well for me. However, the library owner stopped supporting the library, so I need to find other one.

Experimenting with react-aad. I used the example and got nice page that suggests popup or redirect login. However, both do not work. Most likely my configuration contains errors. If I do not provide authority, I get microsoft auth page, not for my tenant. If I provide 'https://x5aaas.b2clogin.com/x5aaas.onmicrosoft.com', as directed by this post, i see error in console "endpoints_resolution_error:Endpoints cannot be resolved".

It seems there are some configuration mistakes:

provider={
    new MsalAuthProviderFactory({
        authority: 'https://x5aaas.b2clogin.com/x5aaas.onmicrosoft.com', 
        clientID: 'a1568977-3095-4bf6-a6d6-c10c87658488',
        scopes: ['https://x5aaas.onmicrosoft.com/ui/use'],
        type: LoginType.Redirect,
        persistLoginPastSession: true,
        postLogoutRedirectUri: window.origin.location,
    })
}

I use basic react app with type script, created with

npx create-react-app <appName> --typescript

What can be wrong here?


Solution

  • The value of the authority is not correct. You should use https://login.microsoftonline.com/tfp/<your-tenant-name>.onmicrosoft.com/<your-sign-in-sign-up-policy>

    The value of your-sign-in-sign-up-policy is the name of the policy.

    enter image description here