Usually this issue occurs when the redirect url defined in azure portal doesn't match the redirect url in your authorize request. You can use fiddler to capture the authorize request url to find the redirect url in the request. Something like
`https://login.microsoftonline.com/{tenant}/oauth2/authorize? client_id=6731de76-14a6-49ae-97bc-6eba6914391e &response_type=code &redirect_uri=http%3A%2F%2Flocalhost%3A12345 &response_mode=query &resource=https%3A%2F%2Fservice.contoso.com%2F &state=12345`
Copy this redirect_uri and paste it to Azure portal.
The reply url in your code must be the same as the one in azure portal.
You can use the fiddler to capture the request url, you will find the redirect_uri in the authorize endpoint. Then use this one in Azure portal.
Something like `https://login.microsoftonline.com/{tenant}/oauth2/authorize? client_id=6731de76-14a6-49ae-97bc-6eba6914391e &response_type=code &redirect_uri=http%3A%2F%2Flocalhost%3A12345 &response_mode=query &resource=https%3A%2F%2Fservice.contoso.com%2F &state=12345`
Copy the value of `redirect_uri`