azureauthenticationazure-static-web-appazure-app-registration

How can i confiure Azure App Registration redirect to requested Url?


I have an Azure Static WebApp that is configured with AAD Authentication through an Azure App Registration. Only members from my organization should be able to view the site.

My staticwebapp.config.json looks like that:

{
    "routes": [
        {
            "route": "/*",
            "allowedRoles": [
                "authenticated"
            ]
        }
    ],
    "responseOverrides": {
        "404": {
            "rewrite": "/404.html",
            "statusCode": 404
        },
        "401": {
            "statusCode": 302,
            "redirect": "/.auth/login/aad"
        }
    },
    "auth": {
        "identityProviders": {
            "azureActiveDirectory": {
                "registration": {
                    "openIdIssuer": "https://login.microsoftonline.com/2e845e2f-11ff-48ec-9861-2fe771a9031d/v2.0",
                    "clientIdSettingName": "AZURE_CLIENT_ID",
                    "clientSecretSettingName": "AZURE_CLIENT_SECRET"
                }
            }
        }
    },
    "globalHeaders": {
        "Cache-Control": "no-cache"
    }
}

When I navigate to https://example.com everything works great.

But when I navigate to any other URL als a link from an other homepage, chat or similar, like https://example.com/important-informations the authentication redirects me back to the homepage https://example.com.

My app registration looks like that: Azure app registration

How can I configure the app registration to redirect to the requested url after authentication?

Thank you for your help!


Solution

  • A college of mine found the answer.

    You have to change the redirect URL in the staticwebapp.config.json.

    Before:

     "401": {
                "statusCode": 302,
                "redirect": "/.auth/login/aad"
            }
    

    After:

     "401": {
                "statusCode": 302,
                "redirect": "/.auth/login/aad?post_login_redirect_uri=.referrer"
            }
    

    The solution was found here: https://github.com/Azure/static-web-apps/issues/738