grant icon indicating copy to clipboard operation
grant copied to clipboard

[Feature request] Extract profile common fields

Open tiaod opened this issue 5 years ago • 1 comments
trafficstars

In the current version, the profile returns the original data

Developers need to write a logic for each provider to extract general information such as username, avatar, id, email, etc.

// Every developer has to write similar code:
let userInfo = {}
switch (grant.provider){
  case 'github':
    userInfo.id = profile.id
    userInfo.avater = profile.avatar_url
    userInfo.nickname = profile.name
    userInfo.email = profile.email
    break
  case 'weibo':
    userInfo.id = profile.id
    userInfo.avatar = profile.profile_image_url
    userInfo.nickname = profile.name
    userInfo.email = profile.email
    break
  case 'qq':
    userInfo.id = profile.openid
    userInfo.avatar = profile.figureurl_2,
    userInfo.nickname = profile.nickname
    break
}

So maybe it's better to let grant extract these common fields and keep the original data to profile.raw

{
  access_token: '...',
  refresh_token: '...',
  profile: {
    id: '123',
    avatar: 'https://.....',
    nickname: 'tiaod',
    email: '[email protected]',
    raw: {
      ... //the raw profile data
    }
  }
}

tiaod avatar Jul 20 '20 07:07 tiaod

That's a good idea, but definitely not a priority.

Having all profile URLs set and tested for all providers, plus any potential fix needed for the underlying HTTP client is a good step forward.

Also keep in mind that we're talking about 180+ providers, and for an endpoint that's largely not standardized, besides the OpenID Connect userinfo one. One thing is to support multiple OAuth implementations that might differ a little, another is to support basically a random endpoint.

simov avatar Jul 20 '20 14:07 simov