c# - Azure AD B2C error - IDX10501: Signature validation failed -
i'm having hard times trying use azure ad b2c authenticate web api. i'll start background
i created mobile application using azure ad b2c authenticate users. i'm creating webview display url:
user asked login azure ad, if login data successfull i'm receiving response containing access token - part went smooth, works properly.
now want create backend web api. created asp net core web application allows me choose authentication method. choose azure ad authentication template generated required data me. relevant part in code here:
i updated required config properties match azure settings. @ point expect able call api using access token received on mobile app. run mobile app locally, signed in, received access token, copied , tried call web api(hosted in iis express) using postman ( authorization header "bearer ..." ). unfortunately no luck - i'm receiving 401 following header:
bearer error="invalid_token", error_description="the signature key not found"
i thought token enough authorize api - understand whole point of oauth. missing ? should have additional config ? noticed config missing sign in policy ( seems required ad b2c name tried adding that:
var validationparameters = new tokenvalidationparameters { authenticationtype = "my_policy", }; app.usejwtbearerauthentication(new jwtbeareroptions { authority = configuration["authentication:azuread:aadinstance"] + configuration["authentication:azuread:tenantid"], audience = configuration["authentication:azuread:audience"], tokenvalidationparameters = validationparameters });
but didn't work too. appreciate help.
edit
i found following error in visual studio logs:
bearer not authenticated. failure message: idx10501: signature validation failed. unable match 'kid': '...'
@juunas comment me find issue. inspected outgoing requests fiddler , found piece of code:
authority = configuration["authentication:azuread:aadinstance"] + configuration["authentication:azuread:tenantid"]
the request being send following address:
https://login.microsoftonline.com/mytenantid/.well-known/openid-configuration
there 2 issues above:
- it's not using v2 endpoint. proper link b2c should use v2 like:
https://login.microsoftonline.com/mytenantid/v2.0/.well-known/openid-configuration
- it not adding sign in policy link ( if set in token options )
i managed make work removing "authority" parameter , changing configure auth function following:
app.usejwtbearerauthentication(new jwtbeareroptions { metadataaddress = string.format("https://login.microsoftonline.com/{0}/v2.0/.well-known/openid-configuration?p={1}", configuration["authentication:azuread:tenantid"], "mypolicy"), authenticationscheme = "mypolicy", audience = configuration["authentication:azuread:clientid"], });
Comments
Post a Comment