Class: OmniAuth::Strategies::Weixin

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/weixin.rb

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/omniauth/strategies/weixin.rb', line 18

def authorize_params
  options[:scope] = "snsapi_userinfo" if options[:scope].nil?

  {
    :appid => options.client_id, 
    :redirect_uri => callback_url, 
    :response_type => 'code', 
    :scope => options[:scope]
  }
end

#build_access_tokenObject



34
35
36
37
38
39
40
# File 'lib/omniauth/strategies/weixin.rb', line 34

def build_access_token
  client.auth_code.get_token(
    request.params['code'],
    {:redirect_uri => callback_url, :parse => :json}.merge(token_params.to_hash(:symbolize_keys => true)),
    {:mode => :query, :param_name => 'access_token'}
  )
end

#raw_infoObject



62
63
64
65
66
67
68
69
# File 'lib/omniauth/strategies/weixin.rb', line 62

def raw_info
  @raw_info ||= begin
    response =  access_token.get(
      '/sns/userinfo',
       {:params => {:openid => uid}, :parse => :json}
    ).parsed
  end
end

#request_phaseObject



14
15
16
# File 'lib/omniauth/strategies/weixin.rb', line 14

def request_phase
  redirect client.authorize_url(authorize_params) + "#wechat_redirect"
end

#token_paramsObject



29
30
31
32
# File 'lib/omniauth/strategies/weixin.rb', line 29

def token_params
  params = super
  params.merge({:appid => options.client_id, :secret => options.client_secret})
end