Class: SimpleWechat::AuthClient
- Inherits:
-
Object
- Object
- SimpleWechat::AuthClient
- Defined in:
- lib/simple_wechat/auth_client.rb
Defined Under Namespace
Classes: AccessToken
Instance Attribute Summary collapse
-
#appid ⇒ Object
readonly
Returns the value of attribute appid.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #authorize_url(redirect_uri, state, options = {}) ⇒ Object
- #connection ⇒ Object
- #get_token(code) ⇒ Object
-
#initialize(appid, secret) ⇒ AuthClient
constructor
A new instance of AuthClient.
Constructor Details
#initialize(appid, secret) ⇒ AuthClient
Returns a new instance of AuthClient.
18 19 20 |
# File 'lib/simple_wechat/auth_client.rb', line 18 def initialize(appid, secret) @appid, @secret = appid, secret end |
Instance Attribute Details
#appid ⇒ Object (readonly)
Returns the value of attribute appid.
16 17 18 |
# File 'lib/simple_wechat/auth_client.rb', line 16 def appid @appid end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
16 17 18 |
# File 'lib/simple_wechat/auth_client.rb', line 16 def secret @secret end |
Instance Method Details
#authorize_url(redirect_uri, state, options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/simple_wechat/auth_client.rb', line 22 def (redirect_uri, state, = {}) scope = [:scope] ||= "snsapi_base" "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{CGI.escape redirect_uri}&response_type=code&scope=#{scope}&state=#{state}#wechat_redirect" end |
#connection ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/simple_wechat/auth_client.rb', line 32 def connection @connection ||= begin conn = Faraday.new do |faraday| faraday.adapter Faraday.default_adapter end end end |
#get_token(code) ⇒ Object
27 28 29 30 |
# File 'lib/simple_wechat/auth_client.rb', line 27 def get_token(code) response = connection.get("https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{appid}&secret=#{secret}&code=#{code}&grant_type=authorization_code") access_token = AccessToken.new MultiJson.load(response.body) end |