Why after authorization request by login.microsoftonline.com user is not redirected to redirect_uri if was not logged in?

Stefan Ejsmont 5 Reputation points

I have a different behavior when I'm using Microsoft Graph autorization and user is logged in or not. I mean when I redirect user to https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize with redirect_uri to my web app in query params and user is logged in to Microsoft account then after authorization user is redirected to url from redirect_uri, but if user has to login to authorize then after login is redirected to office.com account instead of redirection to my web app. Can I force always to redirect to url from redirect_uri?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,880 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Md Asif Muztaba 245 Reputation points Microsoft Vendor

    The behavior you’re experiencing might be due to the way the Microsoft identity platform handles sessions. If a user is already logged in, the platform can directly authenticate the user and redirect them to the specified redirect_uri. However, if the user is not logged in, they are first redirected to the login page and then to the redirect_uri after successful login.

    If the user is being redirected to office.com instead of your redirect_uri after login, it could be due to a misconfiguration in your application settings in the Azure portal<sup>1</sup>. Here are a few things you can check:

    1. Redirect URI: Ensure that the redirect_uri specified in your authorization request matches exactly with one of the Redirect URIs configured in your application settings in the Azure portal. The Redirect URI is case-sensitive and must include the protocol (http:// or https://).
    2. Application ID: Verify that the client_id in your authorization request matches the Application (client) ID of your app in the Azure portal.
    3. Consent: If your app requires user consent, make sure that the user has granted consent. If consent is not granted, the user might be redirected to office.com after login.

    Hope the Above will resolve the issue.