How to add OAuth users via the API - or change the Auth type of existing users

  • What Grafana version and what operating system are you using?
    v8.5.5

  • What are you trying to achieve?
    Automate adding users in a Grafana instance that has OAuth enabled

  • How are you trying to achieve it?
    Adding users is done via the Admin API. The admin API only works with Basic Auth. So we created a separate Grafana instance with Basic Auth that shares the same database. This way I can use the Basic Auth of the latter while my actions are reflected on the former.
    The script uses the Add a new user to the current organization | Grafana documentation call.

  • What happened?
    The users do get added, but they are assigned Basic Auth.

  • What did you expect to happen?
    I expect that at least one of the following exists but I’m not aware of:

    • A parameter such as “authType” in the payload that allows defining which Authentication type the user can use
    • An API endpoint for changing the authentication type for an existing user
  • Can you copy/paste the configuration(s) that you are having problems with?
    N/A

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    N/A

  • Did you follow any online instructions? If so, what is the URL?
    I came across some perhaps related threads e.g. here, here, and here, but there were either no answers or they didn’t apply

1 Like