Class: Baidu::OAuth::Client
- Inherits:
-
Object
- Object
- Baidu::OAuth::Client
- Includes:
- Support::Request
- Defined in:
- lib/baidu/oauth/client.rb
Constant Summary
Constants included from Support::Request
Support::Request::MAX_REDIRECT_LIMIT
Instance Attribute Summary collapse
-
#client_id ⇒ String
申请创建应用后获取的 API Key.
-
#client_secret ⇒ String
申请创建应用后获取的 Secret Key.
Instance Method Summary collapse
-
#code_flow ⇒ Flow::Code
采用 Authorization Code 获取 Access Token 的授权验证流程.
-
#device_flow ⇒ Flow::Device
采用 Device Code 获取 Access Token 的授权验证流程.
-
#initialize(client_id = Baidu.client_id, client_secret = Baidu.client_secret) ⇒ Client
constructor
创建一个 OAuth API 实例.
-
#refresh(token, params = {}) ⇒ Baidu::Session
刷新 Access Token.
Methods included from Support::Request
Constructor Details
#initialize(client_id = Baidu.client_id, client_secret = Baidu.client_secret) ⇒ Client
创建一个 OAuth API 实例
24 25 26 27 28 |
# File 'lib/baidu/oauth/client.rb', line 24 def initialize(client_id=Baidu.client_id, client_secret=Baidu.client_secret) @client_id = client_id @client_secret = client_secret @site = Baidu::OAuth::SITE end |
Instance Attribute Details
#client_id ⇒ String
申请创建应用后获取的 API Key
13 14 15 |
# File 'lib/baidu/oauth/client.rb', line 13 def client_id @client_id end |
#client_secret ⇒ String
申请创建应用后获取的 Secret Key
16 17 18 |
# File 'lib/baidu/oauth/client.rb', line 16 def client_secret @client_secret end |
Instance Method Details
#code_flow ⇒ Flow::Code
采用 Authorization Code 获取 Access Token 的授权验证流程
38 39 40 41 42 |
# File 'lib/baidu/oauth/client.rb', line 38 [:code, :device].each do |flow| define_method("#{flow}_flow".to_sym) do Baidu::OAuth::Flow.const_get(flow.capitalize).new self end end |
#device_flow ⇒ Flow::Device
采用 Device Code 获取 Access Token 的授权验证流程
38 39 40 41 42 |
# File 'lib/baidu/oauth/client.rb', line 38 [:code, :device].each do |flow| define_method("#{flow}_flow".to_sym) do Baidu::OAuth::Flow.const_get(flow.capitalize).new self end end |
#refresh(token, params = {}) ⇒ Baidu::Session
刷新 Access Token
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/baidu/oauth/client.rb', line 53 def refresh(token, params={}) body = { grant_type: 'refresh_token', refresh_token: token, client_id: self.client_id, client_secret: self.client_secret }.update params rest = post Baidu::OAuth::TOKEN_ENDPOINT, nil, body return nil if rest.nil? Baidu::Session.from rest end |