Can Generic OAuth authentication be able to used with other oauth2 provider?

I have an existing rails application and I use doorkeeper gem to have oauth2 provider. I can authorize and redirect to the Grafana, Somehow, it always returns an invalid username or password in Grafana log.

I just found the way to do it.
My objective is

  • I have a rails application using Devise gem for authentication.
  • I have a Grafana dashboard that requires a login.
  • I want to click a button on Rails app and auto login to Grafana using Oauth 2

My Solution

Web app: running on

  • Rails app: I use doorkeeper gem and follow its instruction until I can create a client application for having client_id, client_secret, scope read.

Grafana: running on localhost:3000

  • in grafana.ini, I config the setting like the following
enabled = true
client_id = xxxxxx
client_secret = yyyyyy
scopes = read
auth_url =
token_url =
api_url =
allow_sign_up = true

Web app: routes.rb

use_doorkeeper do
    controllers :token_info => 'token_info'

So in my rails app, I create a controller called token_info_controllers.
I copy all content from doorkeeper token_info_controllers and add customs like the following:

def doorkeeper_token_to_json
    obj = doorkeeper_token.as_json
    obj[:email] = User.find(doorkeeper_token.resource_owner_id).email

Note: I need to add an email because it is required for Grafana while the doorkeeper only returns token info.

1 Like