Github Auth - Server error on Login

What Grafana version are you using?


What datasource are you using?


What OS are you running grafana on?


What did you do?

Configured github authentication using environment variables

What was the expected result?

User should login via github button

What happened instead?

After confirming oauth access in github’s flow, user is redirected to grafana endpoint /login/github which then throws a server error

Include raw network request & response: get by opening Chrome Dev Tools (F12, Ctrl+Shift+I on windows, Cmd+Opt+I on Mac), go the network tab.

Server logs show the following:

t=2018-05-08T19:47:57+0000 lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/login/github status=302 remote_addr= time_ms=0 size=299
t=2018-05-08T19:47:57+0000 lvl=eror msg=login.OAuthLogin(NewTransportWithCode) logger=context userId=0 orgId=0 uname= error="oauth2: server response missing access_token"
t=2018-05-08T19:47:57+0000 lvl=eror msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/login/github status=500 remote_addr= time_ms=224 size=1724
t=2018-05-08T19:48:02+0000 lvl=dbug msg="Scheduling update" logger=alerting.scheduler ruleCount=0
t=2018-05-08T19:48:12+0000 lvl=dbug msg="Scheduling update" logger=alerting.scheduler ruleCount=0

Environment Configuration based on kubernetes grafana.yaml file

        - name: GF_SERVER_ROOT_URL
          value: some root url
        - name: GF_LOG_MODE
          value: "console file syslog"
        - name: GF_LOG_LEVEL
          value: "debug"
        - name: GF_AUTH_GITHUB_ENABLED
          value: "true"
        - name: GF_AUTH_GITHUB_CLIENT_ID
              name: github-credentials
              key: id
              name: github-credentials
              key: secret
          value: "true"
        - name: GF_AUTH_GITHUB_SCOPES
          value: "user:email,read:org"
        - name: GF_AUTH_GITHUB_AUTH_URL
          value: default
        - name: GF_AUTH_GITHUB_TOKEN_URL
          value: default
        - name: GF_AUTH_GITHUB_API_URL
          value: default
          value: some org
          value: "true"
        - name: GF_SECURITY_ADMIN_USER
              name: grafana-credentials
              key: user
              name: grafana-credentials
              key: password
        - name: GF_SMTP_ENABLED
          value: "true"
        - name: GF_SMTP_HOST
          value: some smtp host
        - name: GF_SMTP_USER
              name: smtp-credentials
              key: username
        - name: GF_SMTP_PASSWORD
              name: smtp-credentials
              key: password
        - name: GF_SMTP_FROM_ADDRESS
          value: some email
        - name: GF_SMTP_FROM_NAME
          value: some name

I am running this as part of a kubernetes deployment configuration based on this repo camilb/prometheus-kubernetes

I am also running an elb nginx ingress in front with ssl termination at the elb to enable https traffic routed through Route 53 in AWS.

Let me know if there is anymore information i can provide

1 Like

This error indicates that the response from the Github API did not include a valid access token, but I’m not sure why that would happen.

hello @dcech, I updated my original post with a bit more of my configuration data.

This problem started occuring after I upgraded from 4.6.3 to 5.1.1. I originally upgraded because of the github oauth bug regarding organizations present in earlier versions before 5.0.

Any guidance would be awesome



Did you configure Authorization callback URL for your test/dev Grafana domain+path?
You may try to exchange obtained code for a token with curl to see response from GitHub directly - error message should be there. Curl example:

curl --request POST \
  --url '' \
  --header 'content-type: application/json' \
  --data '{"grant_type":"authorization_code","client_id": "YOUR_CLIENT_ID","client_secret": "YOUR_CLIENT_SECRET","code": "YOUR_AUTHORIZATION_CODE","redirect_uri": "https://YOUR_APP/callback"}'


Thanks for the help @jangaraj

The callback url in github is configured with the following:

Here is the response to that curl command

GitHub response looks good to me.

It looks like it’s failing here: (test has been added 4 months ago). It’s not able to parse access_token. I don’t know why. You may try to add some debugging lines into Go code to see raw GitHub response and parsed access_token values, just to debug golang/oauth2 RetrieveToken() function. Of course, you will need to build your own Grafana binary.

After looking into that code in the oauth2 library I did notice that the response header for content-type does not full text match the expected cases inside the oauth2 package.

Response headers

HTTP/1.1 200 OK
Date: Wed, 09 May 2018 23:10:38 GMT
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Transfer-Encoding: chunked
Status: 200 OK
Cache-Control: no-cache
Vary: X-PJAX
X-Request-Id: eefd32c7-0dbd-4e27-b95f-9df7409773c8
X-Runtime: 0.015145
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Expect-CT: max-age=2592000, report-uri=""
Content-Security-Policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' wss://; font-src; form-action 'self'; frame-ancestors 'none'; frame-src; img-src 'self' data: *; manifest-src 'self'; media-src 'none'; script-src; style-src 'unsafe-inline'
X-Runtime-rack: 0.021266
Vary: Accept-Encoding
X-GitHub-Request-Id: C1E6:0AB1:D3A4D:14AAC2:5AF37FEE

Oauth2 expected content-type values:

content, _, _ := mime.ParseMediaType(r.Header.Get("Content-Type"))
switch content {
case "application/x-www-form-urlencoded", "text/plain":

Notice that the response header contains the charset for content-type? I’m not sure if go’s mime library correctly parses out that data string before it does the comparison in the switch case.

I am also totally bewildered by the fact that no one else seems to be experiencing this issue when using github login.

That is not a problem -

1 Like

I am running into the same problem as described by @chancelarkst.

My grafana is sitting behind an instance of HAProxy. I’ve verified with curl that I can obtain a token from github. This problem seems present in older versions as well as new ones. The issue is occurring when the docker container running grafana is exposed to the internet and when it is behind a load balancer.

1 Like

I have the same problem with grafana 6.2.2 as described by @chancelarkst

Someone solved this problem?

Sorry, My issue is from my bad. It’s not relative from this issue :slight_smile:

I got the same error. I am using ingress-nginx with grafana behind in k8s. I can get access_token using curl, but getting
login.OAuthLogin(missing saved state) inside grafana.
I set cookie_samesite = lax, domain = my.ingress.route, root_url = https://my.ingress.route and cookie_secure = true.
Any updates?

@mjmayer Did you solved problem? How?

I stuck Grafana behind basic auth and called it a day.