Callback from OAuth server results in 500 Internal Server Error when state payload is added

Radosław Ziemniak 11 Reputation points
2022-05-24T12:02:56.437+00:00

I have secured my Azure Function endpoint using built-in Easy Auth in Azure Portal.

Due to different tutorials and knowledge from internet + my requirements - I created App Registration in AD B2C with necessery Redirect URIs on Authentication page, I set ADD Authentication for my Azure Function etc..

I wanted to achieve flow where I am using a prepared link that redirects me to the sign-in page, and after successful login redirects me to my Azure Function endpoint.

Using prepared link https://[myAzureFunction]/.auth/login/aad?post_login_redirect_uri=[AzureFunctionEndpoint] I was able to open my B2C policy login page, register user, let him login etc and at the end redirect him to Azure Function Endpoint. But my problem occured on Reset Password user journey.

We have implemented custom policies in our B2C, and we want to use them for all applications, so in the above flow as well. But when I am trying to let the user go through the Reset Password user journey at the end I am receiving a (500) Internal Server Error.
It is like this probably because when B2C call https://[myAzureFunction]/.auth/login/aad/callback then in payload in 'State' parameter 'redir=[myAzureFunctionEndpoint]' is sent.

205060-ss1.jpg

205077-ss2.jpg

EasyAuth after clicking the link open page with parameters:
https://[tenant]/[domain]/oauth2/v2.0/authorize
?response_type=code+id_token
&redirect_uri=[myAzureFunction]%2f.auth%2flogin%2faad%2fcallback
&client_id=XXX
&scope=openid+profile+email
&response_mode=form_post
&p=[customPolicy]
&nonce=c639d78ac46e476188e37d9856554c7a_20220428173437
&state=redir%3Dhttps[AzureFunctionEndpoint]

But when I prepared the link in this way:
https://[tenant]/[domain]/[customPolicy]/oauth2/v2.0/authorize?
response_type=code+id_token
&redirect_uri=https[myAzureFunction]%2f.auth%2flogin%2faad%2fcallback
&client_id=XXX
&scope=openid+profile+email
&response_mode=form_post
&nonce=defaultNonce
&state=redir%3Dhttps[myAzureFunctionEndpoint]

I was able to not receive 500 Internal Server Error but always only on the first try. When I am redirected to the login page, parameters were set again in a different way and an Error occurred again.

Is there something that I can configure to resolve my problem? I believe that the above is caused by the EasyAuth implementation bug, but maybe there is some way to achieve similar functionality in another way?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,307 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,656 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,601 questions
{count} votes