Class: QqClient::Oauth
- Inherits:
-
Object
- Object
- QqClient::Oauth
- Defined in:
- lib/qq_client/oauth.rb
Constant Summary collapse
- API_URL =
"https://graph.qq.com/"
Class Method Summary collapse
Instance Method Summary collapse
- #get(uid, path, parameters = {}) ⇒ Object
- #get_uid(path, parameters = {}) ⇒ Object
-
#initialize(access_token) ⇒ Oauth
constructor
A new instance of Oauth.
- #post(uid, path, parameters = {}) ⇒ Object
Constructor Details
#initialize(access_token) ⇒ Oauth
Returns a new instance of Oauth.
8 9 10 11 12 |
# File 'lib/qq_client/oauth.rb', line 8 def initialize(access_token) config = QqClient::Config::load_config(nil, nil, nil) @app_key = config[:app_key] @access_token = access_token end |
Class Method Details
.parse_signed_request(signed_request) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/qq_client/oauth.rb', line 35 def self.parse_signed_request(signed_request) encoded_sig, payload = signed_request.split(".") sig = Base64.decode64_url(encoded_sig) begin data = JSON.parse(Base64.decode64_url(payload)) rescue Exception => e return nil end return nil if data["algorithm"].upcase != "HMAC-SHA256" expected_sig = OpenSSL::HMAC.digest("sha256", Config.app_secret, payload) (sig != expected_sig) ? nil : data end |
Instance Method Details
#get(uid, path, parameters = {}) ⇒ Object
14 15 16 17 |
# File 'lib/qq_client/oauth.rb', line 14 def get(uid, path, parameters = {}) parameters.merge!(openid: uid,access_token: @access_token,oauth_consumer_key: @app_key) JSON.parse RestClient.get(api_url(path), :params => parameters) end |
#get_uid(path, parameters = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/qq_client/oauth.rb', line 24 def get_uid(path, parameters = {}) parameters.merge!(access_token: @access_token,oauth_consumer_key: @app_key) callback_function = RestClient.get(get_uid_url(path, parameters)) callback_function.match(/"openid":([^\/.]*)$/).to_a.second.split('"').second end |
#post(uid, path, parameters = {}) ⇒ Object
19 20 21 22 |
# File 'lib/qq_client/oauth.rb', line 19 def post(uid, path, parameters = {}) parameters.merge!(openid: uid,access_token: @access_token,oauth_consumer_key: @app_key) JSON.parse RestClient.post(api_url(path), parameters) end |