Class: WechatClient::OAuth
- Inherits:
-
Object
- Object
- WechatClient::OAuth
- Defined in:
- lib/wechat_client/o_auth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#openid ⇒ Object
readonly
Returns the value of attribute openid.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#unionid ⇒ Object
readonly
Returns the value of attribute unionid.
Class Method Summary collapse
Instance Method Summary collapse
- #auth ⇒ Object
-
#initialize(options) ⇒ OAuth
constructor
A new instance of OAuth.
- #refresh_auth ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ OAuth
Returns a new instance of OAuth.
5 6 7 |
# File 'lib/wechat_client/o_auth.rb', line 5 def initialize set_valuables [:code] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/wechat_client/o_auth.rb', line 3 def access_token @access_token end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/wechat_client/o_auth.rb', line 3 def code @code end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
3 4 5 |
# File 'lib/wechat_client/o_auth.rb', line 3 def expires_in @expires_in end |
#openid ⇒ Object (readonly)
Returns the value of attribute openid.
3 4 5 |
# File 'lib/wechat_client/o_auth.rb', line 3 def openid @openid end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
3 4 5 |
# File 'lib/wechat_client/o_auth.rb', line 3 def refresh_token @refresh_token end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
3 4 5 |
# File 'lib/wechat_client/o_auth.rb', line 3 def scope @scope end |
#unionid ⇒ Object (readonly)
Returns the value of attribute unionid.
3 4 5 |
# File 'lib/wechat_client/o_auth.rb', line 3 def unionid @unionid end |
Class Method Details
.generate_auth_link(url, state = "", scope = "snsapi_userinfo") ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/wechat_client/o_auth.rb', line 28 def self.generate_auth_link url, state = "", scope = "snsapi_userinfo" params = { appid: WechatClient.client..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 |
Instance Method Details
#auth ⇒ Object
9 10 11 12 13 14 15 |
# 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 ⇒ Object
17 18 19 |
# File 'lib/wechat_client/o_auth.rb', line 17 def refresh_auth WechatClient.client.refresh_auth_access_token refresh_token: @refresh_token end |
#valid? ⇒ Boolean
21 22 23 24 25 26 |
# 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 |