Azure AD sign in error reply url

Hi, I’ve been trying to get Azure Active Directory Authentication to work and I’ve followed all the steps in

While I am getting the option to sign in with AAD at the login page, I’m getting the following error:

Sorry, but we’re having trouble signing you in.
AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application: ‘xxx’

Where xxx is application id of the grafana app that I registered in step 3 in the link.
Upon investigating, I found that the reply URL is https://grafana domain/login/generic_oauth in the AAD as it should be, however I noticed that the Request URL on the error page (obtained by pressing F12) contained a redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Flogin%2Fgeneric_oauth

Is this the cause of the issue? Should the redirect_uri instead be http://grafana domain/login/generic_oauth rather than localhost?
If so how do I change the redirect_uri and if not, what could be the cause of this issue?
I am using Grafana 5.1

The redirect url should be the full url (including domain name/port) like

Exactly what I thought, however, in Azure Active Directory I can only set the Reply URL which is
The redirect_uri is being set automatically to http://localhost:port/login/generic_oauth
How do I change the redirect_uri manually?

It sounds like you don’t have your root_url set properly in the [server] section of your Grafana .ini file. If you set that to https://grafana-domain:port/ then it’ll be able to construct self-referential urls correctly.

Hey thanks a lot, this fixed the redirect issue. However the Grafana documentation told me to use reply URL as
but it is only working when I use reply URL as
Should the documentation be corrected or am I doing something wrong? Also I think it would be helpful to mention setting the root_url in the AAD doc for Grafana.