Generic OAuth - Error decoding user info JSON (Grafana + Drupal)

Hi, I’m trying to set up Grafana to use a Drupal site as the OAuth server.

Steps:

  1. Go to my Grafana url
  2. Click on “Sign in with OAuth”
  3. It redirects me to the Drupal site.
  4. I log in on the Drupal site.
  5. I authorize the app if was not previously authorized.
  6. It redirects to my grafana url
  7. Grafana shows error: “login.OAuthLogin(get info from generic_oauth)”

Error I can see on the grafana log:

t=2020-01-16T15:54:26-0500 lvl=eror msg="login.OAuthLogin(get info from generic_oauth)" logger=context userId=0 orgId=0 uname= error="Error decoding user info JSON: json: cannot unmarshal array into Go value of type social.UserInfoJson"

Grafana configuration:

[auth.generic_oauth]
enabled = true
name = OAuth
allow_sign_up = false
scopes = gestor
client_id = [CLIENT_ID]
client_secret = [CLIENT_SECRET]
auth_url = https://example.com/oauth/authorize
token_url = https://example.com/oauth/token
api_url = https://example.com/api/me
email_attribute_path = [0].mail
role_attribute_path = contains([0].roles_target_id, 'Gestor') && 'Admin' || contains([0].roles_target_id, 'Cliente') && 'Viewer'

On the Drupal side I’m using simple_oauth module wich is based on the PHP Library League\OAuth2

The https://example.com/api/me I’ve cofigured in the Drupal site is a REST api point that prints the current user information (I’ve checked the JMESPath and seems to be ok):

[{"name":"username","roles_target_id":"Gestor, Cliente","mail":"user@example.com"}]

I do appreciate any guidance on how to troubleshoot this kind of error, I guess I’m missing some configuration somewhere.

Is maybe because the REST response is an array?

Thanks in advance !

PS: I made sure to have my grafana admin user and Drupal user with the same email.
Update: I’ve modified my Drupal response so it’s easier (less fields).

As I guess, the issue is that Drupal was giving an array and Grafana needs a json object. Maybe is a candidate for a feature request to support that array?

Anyway, I’ve solved the output in Drupal with a custom REST resource plugin.

JSON:

{"user":"username","email":"user@example.com","roles":"gestor, authenticated"}

Grafana config:

api_url = https://example.com/api/me
email_attribute_path = email
role_attribute_path = contains(roles, 'gestor') && 'Admin' || contains(roles, 'cliente') && 'Viewer'