Avatars from the OAuth2 server
It turns out that most auth servers already have images for their users, and they make them available through the protected user resource that we already used in order to get our user's names. To use this avatar picture, we need to get the URL from the provider, store it in the cookie for our user, and send it through a web socket so that every client can render the picture alongside the corresponding message.
Getting the avatar URL
The schema for user or profile resources is not part of the OAuth2 spec, which means that each provider is responsible for deciding how to represent that data. Indeed, providers do things differently; for example, the avatar URL in a GitHub user resource is stored in a field called avatar_url
, whereas in Google, the same field is called picture
. Facebook goes even further by nesting the avatar URL value in a url
field inside an object called picture
. Luckily, Gomniauth abstracts this for us; its GetUser
call on a provider standardizes...