Sha256: d173d4b8f2fab190fdae7e3135aa0777b2bf35f7f8e9d5d605eac01fc4b532e5
Contents?: true
Size: 1.64 KB
Versions: 3
Compression:
Stored size: 1.64 KB
Contents
require 'omniauth/oauth' require 'multi_json' module OmniAuth module Strategies # Authenticate to T163 via OAuth and retrieve basic # user information. # # Usage: # # use OmniAuth::Strategies::T163, 'APIKey', 'APIKeySecret' class T163 < OmniAuth::Strategies::OAuth def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block) @api_key = consumer_key client_options = { :access_token_path => '/oauth/access_token', :authorize_path => '/oauth/authenticate', :realm => 'OmniAuth', :request_token_path => '/oauth/request_token', :site => 'http://api.t.163.com', } super(app, :t163, consumer_key, consumer_secret, client_options, options, &block) end def auth_hash OmniAuth::Utils.deep_merge( super, { 'uid' => user_hash['screen_name'], 'user_info' => user_info, 'extra' => { 'user_hash' => user_hash, }, } ) end def user_info user_hash = self.user_hash { 'username' => user_hash['name'], 'name' => user_hash['realName'], 'location' => user_hash['location'], 'image' => user_hash['profile_image_url'], 'description' => user_hash['description'], 'email' => user_hash['email'], 'urls' => { 'T163' => 'http://t.163.com', }, } end def user_hash @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.163.com/account/verify_credentials.json").body) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
oa-oauth-0.3.2 | lib/omniauth/strategies/oauth/t163.rb |
oa-oauth-0.3.0 | lib/omniauth/strategies/oauth/t163.rb |
oa-oauth-0.3.0.rc3 | lib/omniauth/strategies/oauth/t163.rb |