AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application: '

Viewed 1986

I have created a API app and deployed it to Azure. The app uses Active directory authentication.
I get the following error

AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application: 00000000-0000-4f27-0000-00000000.

Steps so far

  • Enabled Active directory authentication
  • Set CORS to *
  • Set Reply URL to same address https://myapp.azurewebsites.net/
  • I have added the following settings in the web config

config

  <add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}"></add>
    <add key="ida:PostLogoutRedirectUri" value="https://myapp.azurewebsites.net/"></add>

The code for the api is as follows

[HttpGet]
        [SwaggerResponse(HttpStatusCode.OK,
            Type = typeof(IEnumerable<Contact>))]
        public async Task<IEnumerable<Contact>> Get()
        {
            return await GetContacts();
        }
5 Answers

Get a Fiddler trace of what goes through your browser when you try to authenticate to the app. There should be a request to AAD asking for authentication, which will also include a reply url. Make sure it is the same as the one your app is configured with in AAD.

Have you set below key and value on web.config. key="ida:RedirectUri" value="https://myapp.azurewebsites.net/"

Had the same error, the solution was:

Go to the Azure portal: https://portal.azure.com sign in and click on the Azure Active Directory icon on the left. Then click on the ‘App registrations’ icon in the middle pane. In the search box enter the application from the error message and choose ‘All apps’ from the dropdown:

Click on your application, then the Settings icon, select the ‘Reply URLs’ from the list.

Copy One of reply URL and add it in your application as an https port.

You can do that from properties of the project or just add in lounchsetting.json files sslPort value

I had this same issue when following the MS tutorial Call the Microsoft Graph API from a Windows Desktop app. There was no place in my code where I was supplying a redirect url, except on this line

.WithDefaultRedirectUri();

Which upon hovering over it I could see was https://login.microsoftonline.com/common/oauth2/nativeclient, which was a redirect uri that was present on my app on Azure. This was all quite confusing and I did not find an answer anywhere online. After about 3 hours of searching for answers and playing around with many possibilities in the code I found this comment in one of the files I downloaded:

// Requires redirect URI "ms-appx-web://microsoft.aad.brokerplugin/{client_id}" in app registration

So I went to https://ms.portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Authentication/appId/171axxxx-xxxx-xxxx-xxxx-xxxxxxxxafff/isMSAApp/ and under Authentication >Redirect URIs I added the redirect URI ms-appx-web://microsoft.aad.brokerplugin/171axxxx-xxxx-xxxx-xxxx-xxxxxxxxafff.

Next I modified my code like this:

public partial class App : Application
    {
        // Below are the clientId (Application Id) of your app registration and the tenant information. 
        // You have to replace:
        // - the content of ClientID with the Application Id for your app registration
        // - The content of Tenant by the information about the accounts allowed to sign-in in your application:
        //   - For Work or School account in your org, use your tenant ID, or domain
        //   - for any Work or School accounts, use organizations
        //   - for any Work or School accounts, or Microsoft personal account, use common
        //   - for Microsoft Personal account, use consumers
        private static string ClientId = "171axxxx-xxxx-xxxx-xxxx-xxxxxxxxafff";

        // Note: Tenant is important for the quickstart.
        private static string Tenant = "72f9xxxx-xxxx-xxxx-xxxx-xxxxxxxxdb47"; //also works with "common"
        private static string Instance = "https://login.microsoftonline.com/";
        private static IPublicClientApplication _clientApp;


        static App()
        {
            CreateApplication(true);
        }


        public static void CreateApplication(bool useWam)
        {
            //initialize MSAL
            var builder = PublicClientApplicationBuilder.Create(ClientId)
                .WithAuthority($"{Instance}{Tenant}")
                .WithDefaultRedirectUri();

            if (useWam)
            {
                builder.WithExperimentalFeatures();
                builder.WithBroker(true);  // Requires redirect URI "ms-appx-web://microsoft.aad.brokerplugin/{client_id}" in app registration
            }
            _clientApp = builder.Build();
            TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache);
        }

        

        public static IPublicClientApplication PublicClientApp { get { return _clientApp; } }
    }

I don't know why Azure didn't just add this in with the other redirects since they knew it would be needed, or at least include this step in the instructions, but hopefully this will be helpful to someone else experiencing this error.

Related