Azure B2C: Seamless migration custom policy POST request to API not passing the correct body?
I'm configuring a custom policy for seamless migration. I've already done the pre-migration with the temporary password. The flow is:
- When a user Signs in, It will check if
extension_isMigrated
is false. - If
extension_isMigrated == false
, then it will proceed to validate (using the legacy API ServiceUrl using.NET Core 2.1
framework) using{"email": "enteredEmail", "password": "enteredpassword"}
. - If legacy API Validation returns true, then it will update the Password of the User in B2C using the entered password of the user, and authenticate the user (signed-in).
- if legacy API Validation returns false, then send an error message and prevent signin.
I am encountering a problem with the API validation part. B2C can communicate with the API, no problem. The problem is, the payload being sent with the request encounters NullReferenceException
in one of the validation methods.
ASP.NET (C#)
public async Task<bool> Login([FromBody] User user)
{
if (!AllowPasswordLogin(user.email))
}
ASP.NET (C#)
private bool AllowPasswordLogin(string email)
{
string domainName = email.Substring(email.IndexOf("@") + 1); //NullReferenceException
}
Debugging steps:
- I sent a request to
webhooks
via the B2C policy to verify what the payload is and got this JSON
JSONCopy
{
"email": "a",
"password": "a"
}
- I created a postman POST request towards the API with the JSON above as the body and it returns a status 200 with the expected boolean response.
- Spacing on the JSON body doesn't matter, it still returns status 200 when requested through postman. I sent a postman request to
webhooks
to compare headers and I don't see any significant contributor, but I'll include it here as well.
B2C request:
Postman Request:
Based on my investigation, It seems that my API request from B2C should work since it sends the same payload as the one in Postman, but this is not the case. I don't know if there might be something about how B2C is sending the request that's interfering with .NET Core 2.1 model binding, even though the raw JSON payload looks correct.