Class: Oauth::QQ

Inherits:
Provider show all
Defined in:
lib/oauth/provider/qq.rb

Direct Known Subclasses

QQMobile

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Provider

#expired?, #fetch_info!, request, type

Class Method Details

.authenticate?(access_token, uid) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/oauth/provider/qq.rb', line 15

def authenticate?(access_token, uid)
  openid = self.openid(access_token)
  openid && (openid == uid)
end

.authorize_urlObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/oauth/provider/qq.rb', line 27

def authorize_url
  get_params = {
    response_type: 'code',
    client_id: Configure['qq']['appid'],
    redirect_uri: Configure['qq']['callback'],
    state: 1,
    scope: 'get_user_info,get_info,do_like'
  }
  "https://graph.qq.com/oauth2.0/authorize?#{URI.encode_www_form(get_params)}"
end

.detail_of_code(code) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/oauth/provider/qq.rb', line 38

def detail_of_code(code)
  get_params = {
    grant_type: 'authorization_code',
    client_id: Configure['qq']['appid'],
    client_secret: Configure['qq']['secret'],
    code: code,
    redirect_uri: Configure['qq']['callback']
  }
  response = getJSON('https://graph.qq.com/oauth2.0/token', get_params)
  if response # access_token=xxx&expires_in=7776000&refresh_token=xxx
    detail = Hash[response.split('&').map{|q| q.split('=')}]
    detail["created_at"] = Time.now
    detail['uid'] = openid(detail["access_token"])
    if detail['uid']
      detail
    else
      nil
    end
  else
    nil
  end
end

.openid(access_token) ⇒ Object



20
21
22
23
24
25
# File 'lib/oauth/provider/qq.rb', line 20

def openid(access_token)
  str = get('https://graph.qq.com/oauth2.0/me', {access_token: access_token})
  if str
    str.match(%r{"openid":"([A-z0-9]{32})"}).try(:[], 1)
  end
end

Instance Method Details

#api_access(api, http_params = {}, http_method = 'get') ⇒ Object



8
9
10
11
12
# File 'lib/oauth/provider/qq.rb', line 8

def api_access(api, http_params = {}, http_method = 'get')
  url = 'https://graph.qq.com/user/' + api
  http_params.merge!({"access_token" => access_token, "openid"=> uid, "oauth_consumer_key" => Configure['qq']['appid']})
  Oauth::QQ.request(url, http_params, http_method, 'json')
end

#fetch_infoObject



4
5
6
# File 'lib/oauth/provider/qq.rb', line 4

def fetch_info
  api_access('get_user_info')
end