MS Graph: Redirected to the wrong URL when trying to get an access code

George Ivan 0 Reputation points
2023-04-10T07:04:22.1033333+00:00

I have set up an Azure app for which I defined 2 redirect URLs, one for testing on localhost and the other for testing in an online demo environment: http://localhost/myproject/auth and https://demo.myproject.com/auth. In my PHP app I construct this URL to get an authentication code, which I then use to retrieve my access and refresh tokens (line breaks are for readability):

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id=aaaaaaaaa-...-...-...-...
&scope=User.Read+Mail.ReadWrite+offline_access
&response_type=code
&redirect_url=http%3A%2F%2Flocalhost%2Fmyproject%2Fauth   <-- I want to be redirected to localhost
&state=wWpmDDGFZuDAI

After logging in, I should be redirected to http://localhost/myproject/auth, as specified in the URL above, but I'm being redirected to https://demo.myproject.com/auth instead. If I remove https://demo.myproject.com/auth from the Azure app, everything works as expected. As soon as I add it back, I'm being redirected to it, even though the localhost URL is specified as redirect_url. I tried resetting the laptop, clearing the browser cache completely, even installed a new browser and tried logging in from that one, to no success. Why does this happen?

Microsoft Security Microsoft Entra Microsoft Entra ID
Microsoft Security Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. Zehui Yao_MSFT 5,876 Reputation points
    2023-04-11T06:01:32.8233333+00:00

    Hi George Ivan , in my environment, everything is going well, could you please check my app's settings in AD portal to see if this makes any difference. Hope to be able to help you. User's image

    User's image

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Aurel D 0 Reputation points
    2023-05-22T18:37:32.7366667+00:00

    my settings are similar and I am still experiencing the same issue. it ALWAYS redirects to the FIRST URL in the list, doesn't matter where I try to login from and doesn't matter if the redirect URL provided is valid (which it is).

    screencapture-portal-azure-2023-05-22-21_34_06

    0 comments No comments

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.