Closed DCurtin closed 3 years ago
Nevermind, I was doing something incredibly stupid.
In summary for anyone else running into this issue
The above setup works for having b2c host the well-known keys I used issuer from the well-known key => https://{tenant}.b2clogin.com/{tennantId}/v2.0/
To get around AADB2C90209: The provided id_token_hint parameter does not contain an accepted audience. I explicitly set an audience in my policy and matched that in the jwt I was generating.
Hi @DCurtin, I am indeed hitting AADB2C90209. Can you elaborate a bit on the solution "I explicitly set an audience in my policy and matched that in the jwt I was generating" (eg. where are you setting what)?
After a day of checking every configuration possible, I finally found my own specific problem. I hope my info adds to the list of things to check for anyone else who's trying to resolve this.
I had the stupid issue of having the wrong basePolicy configured on my SignIn_With_Magic_Links.xml
, it was still referring to B2C_1A_TrustFrameworkExtensions
instead of my custom B2C_1A_TrustFrameworkExtensions_Magic_Links
.
This caused a mismatch of signing certificate on my app side and validating certificate on the B2C side.
So make sure the basePolicy
points to the correct custom policy.
<BasePolicy>
<TenantId>my-tenant.onmicrosoft.com</TenantId>
<!--
<PolicyId>B2C_1A_TrustFrameworkExtensions</PolicyId>
-->
<PolicyId>B2C_1A_TrustFrameworkExtensions_Magic_Links</PolicyId>
</BasePolicy>
The custom B2C_1A_TrustFrameworkExtensions_Magic_Links.xml
overrides the CryptographicKeys.issuer_secret
values with my uploaded selfsigned certificate
<CryptographicKeys>
<Key Id="issuer_secret" StorageReferenceId="B2C_1A_MagicLinkSelfsignedCertificate" />
</CryptographicKeys>
Now I browse to the openid-configuration
for my magic link policy at https://my-tenant.b2clogin.com/my-tenant.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1A_SIGNIN_WITH_MAGIC_LINKS
.
From there I navigate to the jwks_uri
property value "jwks_uri": "https://my-tenant.b2clogin.com/my-tenant.onmicrosoft.com/discovery/v2.0/keys?p=b2c_1a_signin_with_magic_links",
to find the validation keys available at this endpoint.
The kid
value should now match the kid
value from your jwt id token hint.
{
"keys": [
{"kid":"__YOUR_CERT_THUMBNAIL__","exp":2299761174,"nbf":1668608574,"x5c":
My metadata looks like this
<Metadata>
<!--Sample action required: replace with your endpoint location -->
<Item Key="METADATA">https://my-tenant.b2clogin.com/my-tenant.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1A_SIGNIN_WITH_MAGIC_LINKS</Item>
<Item Key="IdTokenAudience">registered-app-guid</Item>
<Item Key="issuer">https://my-tenant.b2clogin.com/my-tenant-guid/v2.0/</Item>
</Metadata>
Guides I was following https://techcommunity.microsoft.com/t5/azure-developer-community-blog/magic-signin-amp-invitation-mails-in-azure-ad-b2c/ba-p/1198337 and https://github.com/azure-ad-b2c/samples/tree/master/policies/sign-in-with-magic-link
there was another one as well but I can't find it.
I'm generating the JWT from a node server, at one point I noticed I was using ms instead of seconds for nbf/exp after I changed that I started getting a different error code about audience not matching or something. Then after pushing the policy up again (B2C_1A_SIGNIN_WITH_MAGIC_LINK) it started giving me AADB2C90233 again and i'm not sure at this point what the issue is.
is iat required? is iss required? should iss match issuer from https://testinvestmentsponsorportal.b2clogin.com/testinvestmentsponsorportal.onmicrosoft.com/B2C_1A_OIDC/v2.0/.well-known/openid-configuration
I noticed issuer and IdTokenAudience are optional in the policy but https://docs.microsoft.com/en-us/azure/active-directory-b2c/id-token-hint states that aud and iss are required in the hint.
Is there anyway to further debug the issue to find out what exactly is failing? I was trying ApplicationInsights but didn't find the output logs terribly useful, though I definitely could have been overlooking something.
Any assistance would be appreciated.
From B2C_1A_SIGNIN_WITH_MAGIC_LINK
...
I also have another policy B2C_1A_OIDC that hosts the well-known, following the guide from the first link to set those up.
jwk-uri from above well-known https://testinvestmentsponsorportal.b2clogin.com/testinvestmentsponsorportal.onmicrosoft.com/b2c_1a_oidc/discovery/v2.0/keys Ignore the second key, I added that when testing something else, the first key is the one related to the secret that I'm using for signing. This key originated from a self-signed key generated in powershell kid=>5E9A83B7800B761E1718A156103B712456C3D92C
powershell command
server-side generated hint
B2C_1A_signin_with_magic_link Full Policy