Sha256: 8a41a6496ef06f8a4c0da5d5407ed0a28d20ef193edc65fac2f1b2eb7388480a
Contents?: true
Size: 1.61 KB
Versions: 5
Compression:
Stored size: 1.61 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 = { :site => 'http://api.t.163.com', :request_token_path => '/oauth/request_token', :access_token_path => '/oauth/access_token', :authorize_path => '/oauth/authenticate', :realm => 'OmniAuth' } 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'], '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
5 entries across 5 versions & 1 rubygems