It looks like you could do this by expanding the various classes of Sorcery providers to add application-specific fields for a hash of user information.
For example, to use Twitter, you might have something like this:
config.external_providers = [:twitter]
You can change this to:
config.external_providers = [:TwitterWithAvatar]
Now you need to define the TwitterWithAvatar provider in the Sorcery::Providers section and override the #get_user_hash method:
module Sorcery module Providers class TwitterWithAvatar < Twitter def get_user_hash(access_token) user_hash = super user_hash.merge( avatar: get_avatar(user_hash[:uid]), ) end private def get_avatar(uid) # Some Twitter API call end end end end
Now you can configure your mapping:
config.TwitterWithAvatar.user_info_mapping = {avatar: "avatar"}
Alternatively, since you are already using a custom provider class, you can transfer your mapping to this class:
module Sorcery module Providers class TwitterWithAvatar < Twitter def user_info_mapping { avatar: "avatar", # ... } end end end end
(I have not tried using this code, so the details may be a bit off, but reading the Sorcery source code, it looks like the right direction.)
georgebrock
source share