class WechatClient::OAuth
Attributes
access_token[R]
code[R]
expires_in[R]
openid[R]
refresh_token[R]
scope[R]
unionid[R]
Public Class Methods
generate_auth_link(url, state = "", scope = "snsapi_userinfo")
click to toggle source
# File lib/wechat_client/o_auth.rb, line 28 def self.generate_auth_link url, state = "", scope = "snsapi_userinfo" params = { appid: WechatClient.client.options.app_id, redirect_uri: url, response_type: "code", scope: scope, state: state } "https://open.weixin.qq.com/connect/oauth2/authorize?#{params.to_query}#wechat_redirect" end
new(options)
click to toggle source
# File lib/wechat_client/o_auth.rb, line 5 def initialize options set_valuables options[:code] end
Public Instance Methods
auth()
click to toggle source
# File lib/wechat_client/o_auth.rb, line 9 def auth if @scope == "snsapi_base" WechatClient.client.base_info openid: @openid else WechatClient.client.auth_info access_token: @access_token, openid: @openid end end
refresh_auth()
click to toggle source
# File lib/wechat_client/o_auth.rb, line 17 def refresh_auth WechatClient.client.refresh_auth_access_token refresh_token: @refresh_token end
valid?()
click to toggle source
# File lib/wechat_client/o_auth.rb, line 21 def valid? WechatClient.client.auth_access_token_validation access_token: @access_token,\ openid: @openid do |json| json["errmsg"].downcase == "ok" end end
Private Instance Methods
set_valuables(code)
click to toggle source
# File lib/wechat_client/o_auth.rb, line 41 def set_valuables code @code = code WechatClient.client.auth_access_token code: @code do |json| json.each do |k, v| instance_variable_set "@#{k}", v end end end