Back

Oauth Avatars

  • 0
  • Accounts
  • Web
larkx
5 Jul, 2023, 15:14

Is there a way to fetch the avatar of an Oauth user account? Or in general, is there avatar functionality within Appwrite? A lot of Oauth providers such as Google, Discord and Github all have avatars built into the Oauth system and it would be a nice to be able to access those.

TL;DR
The user is asking if there is a way to fetch the avatar of an OAuth user account in Appwrite. They also mention that some OAuth providers like Google, Discord, and Github have avatars built into their systems. The user suggests creating an Appwrite function that is triggered on the user creation event to fetch the user's avatar from third-party providers like Gravatar. There doesn't seem to be a built-in avatar functionality in Appwrite at the moment.
Binyamin
5 Jul, 2023, 15:24

Theory

As of now Appwrite OAuth is used in a very genral way. Which means that the use of the OAuth2 is to eliminate the need of remembering passwords. But, eventually the login is attached to an email.

You can take a look on all the available Appwrite OAuth2 providers here https://github.com/appwrite/appwrite/tree/master/src/Appwrite/Auth/OAuth2 And, you can see that are treated in a general way to fetch the email (and name) of the user.

That's why when a user is logged in using Github for example, the next day the login can be made through Google and same user will be fetched back as the connection is through the email.

I wasn't able to find any feature request regard that matter, and it sound great feature to have.

Some solution

For now, the best workaround will be to create an <:functions:1108648038156746792> Appwrite function that will be triggered on the user creation event users.*.create then you can try to fetch the current user gravater. For example in js using the JavaScript MD5 pacakge https://www.npmjs.com/package/blueimp-md5

TypeScript
function getUserGravater(email, size = 100){
  retrun 'http://www.gravatar.com/avatar/' + md5(email) + '.jpg?s=' + size;
}

To find out about function events check this: https://appwrite.io/docs/events

Drake
6 Jul, 2023, 04:29

After creating an oauth2 session, the session has a provider access token that can be used to make API calls to the provider and fetch an avatar (if they have one).

See https://appwrite.io/docs/models/session

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more