Search code examples
azureazure-active-directoryazure-authentication

How to pass query string params or POST data to a redirected site when using Azure AD for login in between?


If I am redirecting from one site to another with some query string params or Form POST data. But on redirection, I need the user to login through Azure AD authentication (https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-how-to-configure-active-directory-authentication). How to enable the query string params and the POST data to be passed to the target site after successfully logging through Azure AD. (Does redirection after Azure AD authentication drops the query string params and the Form Post data?)


Solution

  • You can use the "state" value in the login url to store these kinds of properties. Here is an example of the login url:

    // Line breaks for legibility only
    
    https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
    client_id=6731de76-14a6-49ae-97bc-6eba6914391e
    &response_type=code
    &redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
    &response_mode=query
    &scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
    &state=12345
    

    Read more here:

    state

    A value included in the request that will also be returned in the token response. It can be a string of any content that you wish. A randomly generated unique value is typically used for preventing cross-site request forgery attacks. The state is also used to encode information about the user's state in the app before the authentication request occurred, such as the page or view they were on.

    Let me know if this helps!