How to set profile picture/avatar when logging in with generic oauth provider?

How can I automatically set a user’s profile picture/avatar when they log in via a generic oauth provider?

Is it a field in the userinfo schema that grafana reads? Is this something standard in userinfo fields? Sorry that I might be missing some general experience in this regard, but I tried looking into the grafana source code regarding this but didn’t see anything that stuck out to me as the relevant part of the code to answer the question. I suspect it may not be possible, but it would be nice to confirm this – perhaps I may even be able to contribute back if I figure out why/where in the codebase this limitation exists.

thanks for reading!

1 Like

Interested as well. Is this possible for generic oauth? The url of the avatar is already in the userinfo of our IDP.

+1
Have you found any solutions?

Old post I know, but for those that find this via Google. Grafana avatars are grabbed from a site called gravatar.com. Basically, the email associated to a users account is checked against that site’s database and the picture is procured from there.

Pretty cool for individual users. Problem is, if you want custom avatars for Teams, you would have to take the following steps:

  1. add those Teams’ emails to an existing Gravatar profile (in Gravatar, a single account can have multiple emails associated with it and each email can have their own avatar). Problem with that is that if you want custom avatars for all of your teams, you’d first have to do this:
  2. setup some kind of central Gravatar account using something like a Grafana Admin email account (because you wouldn’t want to manage all the teams under an individual user’s Gravatar account for obvious reasons…),
  3. Then, add each of those Teams’ emails as additional emails to your company’s central Gravatar Grafana Admin account,
  4. Then, have someone from each of those Teams forward you the confirmation email so you can login using the Gravatar Grafana Admin account to finally associate it with your account…
  5. Now you can finally upload and assign custom avatars to each team email…
  6. Each additional team added to Grafana in the future will have to go through steps 3, 4, and 5…

What a cumbersome initial process and also a cumbersome process to have to document and pass down to other admins now and in the future.

I’m not saying Grafana shouldn’t offer this service as an option, but they should also offer an option for us to set our own Avatar’s in the tool (preferably in the web console, but at least in a way similar to the White Labeling customization in the product). At least for Teams… I want my Grafana console to look as professional as possible since the main reason we got it is to provide beautiful single-pane-of-glass dashboards to our users and executives and having nice little custom icons throughout the product for Users and Teams would be a nice touch.

1 Like

Is this external service configurable at all, e.g. set the gravatar API base URL or host name?

No. The only “configuration” option I’ve seen is the ability to turn it on or off. Other posts I’ve found while researching this have verified that there is no other way to do avatars for users/teams in Grafana and there is no other customization you can do. It’s Gravatar or nothing…

Kind of crazy.

that would be a cool feature to submit or recommend

image

Wonder where this endpoint is getting the avatar from? interesting it is just a randomized hash

func GetGravatarUrl(text string) string {
	if setting.DisableGravatar {
		return setting.AppSubUrl + "/public/img/user_profile.png"
	}

	if text == "" {
		return ""
	}

	hash, _ := GetGravatarHash(text)
	return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hash)
}

func GetGravatarHash(text string) ([]byte, bool) {
	if text == "" {
		return make([]byte, 0), false
	}

	hasher := md5.New()
	if _, err := hasher.Write([]byte(strings.ToLower(text))); err != nil {
		mlog.Warn("Failed to hash text", "err", err)
	}
	return hasher.Sum(nil), true
}

func GetGravatarUrlWithDefault(text string, defaultText string) string {
	if text != "" {
		return GetGravatarUrl(text)
	}

	text = regNonAlphaNumeric.ReplaceAllString(defaultText, "") + "@localhost"

	return GetGravatarUrl(text)
}

so this could be modified to fetch the avatar from an external resource. doable but I assume it will require some work.

modified the user profile default image and this is what we get

image