redirect uri returns wrong uri

Søren Brønsted 1 Reputation point
2022-01-24T12:37:26.893+00:00

In Azure AD for out Company (borsen.dk)

on App > Authentication > Platform configurations > Web > Redirect URIs

I have configured 2 redirect uri for 2 different environments - test and production, but every time I login from the test environment the AAD redirects to the production environment even though the redirect url parameter is the url to the test environment. If I remove the production environment, it works.

Any explanation on this odd behavior?

Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
13,547 questions
{count} votes

1 answer

Sort by: Most helpful
  1. James Hamil 12,976 Reputation points Microsoft Employee
    2022-02-01T20:37:59.04+00:00

    Hi @Søren Brønsted ,

    I understand that you are being directed to the wrong URL. You need to specify the redirect URI in the login URL and specify where the user and authorization code should be redirected. If you don't specify a Redirect URI in the Login URL, the user will be redirected to the first URL specified in the app's registration.

    To resolve this, you can follow the example in the Authorization Code Grant Flow documentation to specify the Redirect URI:

    https://login.microsoftonline.com/{tenant}/oauth2/authorize?
    client_id=xxxxxx
    &response_type=code
    &redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
    &response_mode=query
    &resource=https%3A%2F%2Fservice.contoso.com%2F
    &state=12345

    Otherwise you could list the URL that you want as the first one in the registration.

    Let me know if you have further questions.

    Additional reading: https://stackoverflow.com/questions/46917919/azure-ad-reply-url-how-to-add-several-urls-when-using-openid-connect-auth