Class: OmniAuth::Strategies::WeChat

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

Instance Method Summary collapse

Methods inherited from OAuth2

#callback_phase, #callback_url

Instance Method Details

#authorize_paramsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/omniauth/strategies/wechat.rb', line 40

def authorize_params
  params = options.authorize_params.merge({
    appid: options.client_id,
    redirect_uri: callback_url,
    response_type: 'code',
    scope: request.params['scope'] || 'snsapi_login',
  })
  if OmniAuth.config.test_mode
    @env ||= {}
    @env["rack.session"] ||= {}
  end
  unless options.provider_ignores_state
    params[:state] = SecureRandom.hex(24)
    session["omniauth.state"] = params[:state]
  end
  params
end

#raw_infoObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omniauth/strategies/wechat.rb', line 22

def raw_info
  @raw_info ||= begin
                  response = access_token.get(
                    '/sns/userinfo',
                    { params: { access_token: access_token.token,
                                openid: access_token['openid'],
                                lang: 'zh-CN' },
                                parse: :json }
                  ).parsed
                  log :debug, response
                  response
                end
end

#request_phaseObject



36
37
38
# File 'lib/omniauth/strategies/wechat.rb', line 36

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

#token_paramsObject



58
59
60
# File 'lib/omniauth/strategies/wechat.rb', line 58

def token_params
  { appid: options.client_id, secret: options.client_secret }
end