Azure AD OAuth - '<' looking for beginning of value

So I’m trying to set up an SSO between our Grafana-server and our Azure AD but I’m not getting anywhere.

I started by following the guide here: Azure AD OAuth2 authentication | Grafana Labs which is really straight forward but I’m still presented with an error afterwards. The error I receive when trying to login with SSO is the following in the GUI: login.OAuthLogin(NewTransportWithCode)

If I check the logs I get this:

t=2021-03-30T21:08:50+0000 lvl=eror msg=login.OAuthLogin(NewTransportWithCode) logger=context userId=0 orgId=0 uname= error=“invalid character ‘<’ looking for beginning of value”

t=2021-03-30T21:08:50+0000 lvl=eror msg=“Request Completed” logger=context userId=0 orgId=0 uname= method=GET path=/login/azuread status=500 remote_addr=192.168.176.1 time_ms=102 size=1744 referer=https://login.microsoftonline.com/

My scouring of the internets have told me that the invalid character error comes from the fact that an HTML-page is returned instead of JSON. But the question is why?

I followed the above mentioned guide and my Docker-config looks like this:

- GF_AUTH_AZUREAD_NAME=Azure AD
- GF_AUTH_AZUREAD_ENABLED=true
- GF_AUTH_AZUREAD_ALLOW_SIGN_UP=true
- GF_AUTH_AZUREAD_CLIENT_ID=<application id>
- GF_AUTH_AZUREAD_CLIENT_SECRET=<client secret>
- GF_AUTH_AZUREAD_SCOPES=openid email profile
- GF_AUTH_AZUREAD_AUTH_URL=https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/authorize
- GF_AUTH_AZUREAD_TOKEn_URL=https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/token
- GF_AUTH_AZUREAD_ALLOWED_DOMAINS=
- GF_AUTH_AZUREAD_ALLOWED_GROUPS=

As far as I can tell this is how it should be according to the documentation. What am I doing wrong or what can I do to try and get more meaningfull information for troubleshooting?

Please do a standard troubleshooting: increase log level and check logs again.

Sorry, was a bit tired yesterday and missed stating that I’ve tried increasing the log level to debug but I don’t get any more information.

Theese messages are all I get regardless of log level (that are related to this problem):

t=2021-03-31T06:27:43+0000 lvl=info msg=“Request Completed” logger=context userId=0 orgId=0 uname= method=GET path=/ status=302 remote_addr=192.168.208.1 time_ms=0 size=29 referer=

t=2021-03-31T06:27:43+0000 lvl=info msg=“OAuth auto login enabled. Redirecting to /login/azuread”

t=2021-03-31T06:27:43+0000 lvl=info msg=“Request Completed” logger=context userId=0 orgId=0 uname= method=GET path=/login status=307 remote_addr=192.168.208.1 time_ms=8 size=50 referer=

t=2021-03-31T06:27:43+0000 lvl=info msg=“Request Completed” logger=context userId=0 orgId=0 uname= method=GET path=/login/azuread status=302 remote_addr=192.168.208.1 time_ms=0 size=365 referer=

t=2021-03-31T06:27:44+0000 lvl=info msg=“state check” logger=oauth queryState=a65a430d3d9601ddc276760391907013e1608f757763c09b86ff6cefd9aae1d1 cookieState=a65a430d3d9601ddc276760391907013e1608f757763c09b86ff6cefd9aae1d1

t=2021-03-31T06:27:44+0000 lvl=eror msg=login.OAuthLogin(NewTransportWithCode) logger=context userId=0 orgId=0 uname= error=“invalid character ‘<’ looking for beginning of value”

t=2021-03-31T06:27:44+0000 lvl=eror msg=“Request Completed” logger=context userId=0 orgId=0 uname= method=GET path=/login/azuread status=500 remote_addr=192.168.208.1 time_ms=121 size=1744 referer=https://login.microsoftonline.com/

Use browser console and check whole login process - request/responses (some idps returns also error in the URL) - html may indicates a problem and error is returned in the html page.

Unfortunately nothing obvious appeared in the console. Only this:

https://my-grafana-url.tld/login/azuread?code=0.AYIAfViNVThKuEyqBgcUjLZyjquWJWDdr41GuX4LtCYXsJyCAM4.AQABAAIAAAD--DLA3VO7QrddgJg7WevrBgK_rgRZljnKkH5wDHaF7i23cu_RjDk2E-VwpTf9q0A0AQZmCQzuhoKFovMc2UHpiNhxTBVBdYHM93bnxS9H6EQ5fhlz_iy-1brlc90Z_pfZ3tFnT90eUbFQpxAnWzdRugH9m4yyyNydeUv3tcbjUl8EGFPeeJDD5C2h9L985DqHdRqLAfYJFVclIUZHsWD19O427TsgyW8GWfYb-UEEur5wBMRI3xD5aSq2W4iww6_WXLnfBD2j0cOqeEis3L-tSCsPNHFuV7NogX6cPvdy18f3ocKxtkI6ScZldsioJBWUoceoM6gn8gnlWhv9GClORSPKABlKDwU9PkgQ6jWcLgaaDsDZ5wtxWI5Qpz0qi8f6BadVZ4e5Czv4mCni4mCYINkjWi5at3WLV2-pCUbRomCGPG2du6ZBm6sh2C2svYqUtZQCVmMSx7zEmoiJzXR45NuKXqCYOBbpHVIYfn2uEY9xMYAC04wmxniuMOxFnT_lV-zWtTVAzHMMsvespUhAmnGRL6gsTgCBULGwpDRpVVAt3xjBdx1ej4oRFVxgZGZigTp0YRpFQw-Zqbt6DFLYuUCuKevoW3yDS4JlC8xqtrbjebVqgvgOkzVEREbgku6nMuG3_wkUadT4SUjYnT7v-kL5tnWFlSiRl2xVatd3X9UsWdftvnQ0f4rFQPlLhoI2mxgUY5WG_bhjU2h-_EKd8abnoFZErANojzuG-aFFZWq4gYceUaY8w4So8ukntZGajYqhFhv28TVsKNuQ3kXKzEmOaGQz9LQNJ9C_XDK7w3U5Fw3vFPMzl_uVLlcjjk1CODMgcKe0ZTbvT1cdQpJPIAA&state=80WMusNr4-uq1EKQ7OAFQqVx-r6R_O-5_gRnfSh055w%3D&session_state=327eea01-1721-4f3b-97b8-bf0917712c35 500

Which can be expanded and reveal:

(anonymous) @ login.microsoftonlin…ae7b-e2f488055dd4:4

Neither of them tell me much, perhaps for someone else?

Did you really use lowercase n in the env variable?

Pat yourself on the back! The tragic truth is that there was indeed a lowercase n that had snuck into the variable name. Change it to all uppercase and everything works. (Note to self: you aren’t supersmart at 11.00 pm)

Thank you for your help in spotting this silly mistake.