简体   繁体   中英

Azure b2c .Net core backend is always giving a 401, front react access token front end

I have a react front-end that sits behind a login with azure b2c, it allows the user to log in if they are registered in my tenant.

I then sent a access token to my backed which i receive using "react-aad-msal":

signInAuthProvider.getAccessToken({
  scopes: ["https://tenantname.onmicrosoft.com/api/scope_name"],
});

When i send this token via a bearer-auth header to my .net core 3.1 back-end i receive a 401.

I am using the addazureadbearer service:

services.AddAuthentication(AzureADDefaults.JwtBearerAuthenticationScheme)
            .AddAzureADBearer(options => Configuration.Bind("AzureAd", options));

and my config section looks liek this:

  "AzureAd": {
"Instance": "https://login.microsoftonline.com/tenantname",
"TenantId": "tenantid",
"ClientId": "clientid",
"Audience": "https://tenantname.onmicrosoft.com/api/api.access"

}

i believe it is doing some sort of cross check as i get a 401 not a error being able to connect to azure.

You need to Authenticate with b2c, not with AAD

{
      "AzureAdB2C": {
        "Instance": "https://<your tenant name>.b2clogin.com",
        "ClientId": " your client id",
        "Domain": "your tenant domain",
    "TenantId": "your tenant id",
        "SignUpSignInPolicyId": "your policy name"
      }

Please refer to this github on .net core web API in b2c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM