Invalid_Grant AADB2C90085 error while using B2C Custom Policy with Google, FB and Azure AD as IdP

Anand Patil 95 Reputation points
2024-10-08T09:32:04.81+00:00

I have an Azure AD B2C Custom Policy defined in my B2C tenant. There are three identity providers configured in the same - Google, Facebook and Azure AD. The custom policy also has four custom attributes which are populated using a rest api endpoint configured in the policy itself. Verified that this setup works fine using jwt.ms.

My main web application is hosted in AWS and has a cloudfront url. This application uses Cognito user pool, and cognito is configured to make use of the above B2C Custom Policy as a federated identity provider. The 'Allowed callback URL' setting for the cognito user pool is the cloudfront url my web application. (https://mycloudfronturl.cloudfront.net/redirectapp)

Redirect uri configured in Azure AD B2C is the AWS Cognito domain url appended with /oauth2/idpresponse. (https://myuserpool.auth.ap-south-1.amazoncognito.com/oauth2/idpresponse)

When I try to do an end-to-end test for this setup, it seems the authentication goes fine, however when the user is redirected to my web application's cloudfront url, I see errors in console which says -
{Federated Identity provider name in AWS Cognito user pool}+Error+-+400+invalid_grant+AADB2C90085:+The+service+has+encountered+an+internal+error.+Please+reauthenticate+and+try+again.

The redirect url's have been double checked and they are correct.

What will be the root cause of this issue and how do I get it resolved quickly ?

Any quick pointers are highly appreciated.

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Azure | Azure Startups
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2024-10-08T12:15:06.7033333+00:00

    Hi @Anand Patil ,

    Thank you for reaching out.

    In reference to our previous discussion (https://learn.microsoft.com/en-us/answers/questions/1792571/azure-ad-b2c-custom-policy-as-a-federated-identity), you were able to resolve the 400 Bad Request error by making the necessary configuration adjustments.

    At that time, the only variation in the configuration was that you were using https://jwt.ms as the Allowed Callback URL.

    The new callback URL should not impact the authentication process. However

    1.Ensure that the Redirect URI in Azure AD B2C (configured in your custom policy) exactly matches the Cognito callback URL: https://myuserpool.auth.ap-south-1.amazoncognito.com/oauth2/idpresponse.

    1. Ensure that the Allowed Callback URL in AWS Cognito matches the URL of your CloudFront distribution where the app is hosted: https://mycloudfronturl.cloudfront.net/redirectapp.

    Sometimes, even small differences in case, trailing slashes, or URL encoding can lead to mismatches. Double-check that they match exactly.

    Could you also confirm if the setup is still working with jwt.ms and only encountering errors with the CloudFront URL?

    Hope this will help.

    Thanks,

    Shweta


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.