You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
module OmniAuth
|
|
module Strategies
|
|
class QQ < OmniAuth::Strategies::OAuth2
|
|
option :client_options, {
|
|
site: 'https://graph.qq.com',
|
|
authorize_url: '/oauth2.0/authorize',
|
|
token_url: '/oauth2.0/token'
|
|
}
|
|
|
|
def request_phase
|
|
super
|
|
end
|
|
|
|
def authorize_params
|
|
super.tap do |params|
|
|
%w[scope client_options].each do |v|
|
|
if request.params[v]
|
|
params[v.to_sym] = request.params[v]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
uid { raw_info['openid'].to_s }
|
|
|
|
info do
|
|
{
|
|
name: user_info['nickname'],
|
|
nickname: user_info['nickname'],
|
|
image: user_info['figureurl_qq_1']
|
|
}
|
|
end
|
|
|
|
extra do
|
|
{ raw_info: user_info }
|
|
end
|
|
|
|
def raw_info
|
|
access_token.options[:mode] = :query
|
|
@raw_info ||= access_token.get('/oauth2.0/me').parsed
|
|
end
|
|
|
|
def user_info
|
|
access_token.options[:mode] = :query
|
|
params = { oauth_consumer_key: options.client_id, openid: raw_info['openid'], format: 'json' }
|
|
@user_info ||= access_token.get('/user/get_user_info', params: params)
|
|
end
|
|
end
|
|
end
|
|
end
|