forked from omniauth/omniauth
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge remote-tracking branch 'quake/master'
Conflicts: oa-oauth/lib/omniauth/oauth.rb
- Loading branch information
Showing
13 changed files
with
499 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'omniauth/oauth' | ||
require 'multi_json' | ||
|
||
module OmniAuth | ||
module Strategies | ||
# | ||
# Authenticate to Douban via OAuth and retrieve basic | ||
# user information. | ||
# | ||
# Usage: | ||
# | ||
# use OmniAuth::Strategies::Douban, 'APIKey', 'APIKeySecret' | ||
# | ||
class Douban < OmniAuth::Strategies::OAuth | ||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) | ||
# Although in OAuth spec the :realm parameter is optional, | ||
# it is required for Douban. | ||
client_options = { | ||
:site => 'http://www.douban.com', | ||
:request_token_path => '/service/auth/request_token', | ||
:access_token_path => '/service/auth/access_token', | ||
:authorize_path => '/service/auth/authorize', | ||
:realm => 'OmniAuth' | ||
} | ||
|
||
super(app, :douban, consumer_key, consumer_secret, client_options, options, &block) | ||
end | ||
|
||
def auth_hash | ||
OmniAuth::Utils.deep_merge(super, { | ||
'uid' => @access_token.params[:douban_user_id], | ||
'user_info' => user_info, | ||
'extra' => {'user_hash' => user_hash} | ||
}) | ||
end | ||
|
||
def user_info | ||
user_hash = self.user_hash | ||
|
||
location = user_hash['location'] ? user_hash['location']['$t'] : nil | ||
image = user_hash['link'].find {|l| l['@rel'] == 'icon' }['@href'] | ||
douban_url = user_hash['link'].find {|l| l['@rel'] == 'alternate' }['@href'] | ||
{ | ||
'username' => user_hash['db:uid']['$t'], | ||
'name' => user_hash['title']['$t'], | ||
'location' => location, | ||
'image' => image, | ||
'description' => user_hash['content']['$t'], | ||
'urls' => { | ||
'Douban' => douban_url | ||
} | ||
} | ||
end | ||
|
||
def user_hash | ||
@user_hash ||= MultiJson.decode(@access_token.get('http://api.douban.com/people/%40me?alt=json').body) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'omniauth/oauth' | ||
require 'multi_json' | ||
|
||
module OmniAuth | ||
module Strategies | ||
# | ||
# Authenticate to qzone (QQ) via OAuth and retrieve basic | ||
# user information. | ||
# | ||
# Usage: | ||
# | ||
# use OmniAuth::Strategies::Qzone, 'consumerkey', 'consumersecret' | ||
# | ||
class Qzone < OmniAuth::Strategies::OAuth | ||
# Initialize the middleware | ||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) | ||
client_options = { | ||
:site => 'http://openapi.qzone.qq.com', | ||
:request_token_path => '/oauth/qzoneoauth_request_token', | ||
:access_token_path => '/oauth/qzoneoauth_access_token', | ||
:authorize_path => '/oauth/qzoneoauth_authorize', | ||
:scheme => :query_string, | ||
:http_method => :get | ||
} | ||
|
||
options[:authorize_params] = {:oauth_consumer_key => consumer_key} | ||
super(app, :qzone, consumer_key, consumer_secret, client_options, options) | ||
end | ||
|
||
#HACK qzone is using a none-standard parameter oauth_overicode | ||
def consumer_options | ||
@consumer_options[:access_token_path] = '/oauth/qzoneoauth_access_token?oauth_vericode=' + request['oauth_vericode'] if request['oauth_vericode'] | ||
@consumer_options | ||
end | ||
|
||
def callback_phase | ||
session['oauth'][name.to_s]['callback_confirmed'] = true | ||
super | ||
end | ||
|
||
def auth_hash | ||
ui = user_info | ||
OmniAuth::Utils.deep_merge(super, { | ||
'uid' => ui['uid'], | ||
'user_info' => ui, | ||
'extra' => {'user_hash' => user_hash} | ||
}) | ||
end | ||
|
||
def user_info | ||
user_hash = self.user_hash | ||
{ | ||
'uid' => @access_token.params[:openid], | ||
'nickname' => user_hash['nickname'], | ||
'name' => user_hash['nickname'], | ||
'image' => user_hash['figureurl'], | ||
'urls' => { | ||
'figureurl_1' => user_hash['figureurl_1'], | ||
'figureurl_2' => user_hash['figureurl_2'], | ||
} | ||
} | ||
end | ||
|
||
def user_hash | ||
@user_hash ||= MultiJson.decode(@access_token.get("/user/get_user_info?format=json&openid=#{@access_token.params[:openid]}").body) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require 'omniauth/oauth' | ||
require 'multi_json' | ||
require 'digest/md5' | ||
require 'net/http' | ||
|
||
module OmniAuth | ||
module Strategies | ||
# Authenticate to Renren utilizing OAuth 2.0 and retrieve | ||
# basic user information. | ||
# | ||
# @example Basic Usage | ||
# use OmniAuth::Strategies::Renren, 'client_id', 'client_secret' | ||
class Renren < OAuth2 | ||
# @param [Rack Application] app standard middleware application parameter | ||
# @param [String] client_id the application id as [registered on Renren](http://dev.renren.com/) | ||
# @param [String] client_secret the application secret as registered on Renren | ||
# @option options [String] :scope ('publish_feed,status_update') comma-separated extended permissions such as `publish_feed` and `status_update` | ||
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block) | ||
client_options = { | ||
:site => "http://graph.renren.com/", | ||
:authorize_url => "/oauth/authorize", | ||
:access_token_url => "/oauth/token" | ||
} | ||
|
||
super(app, :renren, client_id, client_secret, client_options, options, &block) | ||
end | ||
|
||
def user_data | ||
@data ||= MultiJson.decode(Net::HTTP.post_form(URI.parse('http://api.renren.com/restserver.do'), signed_params).body)[0] | ||
end | ||
|
||
def signed_params | ||
params = {} | ||
params[:api_key] = client.id | ||
params[:method] = "users.getInfo" | ||
params[:call_id] = Time.now.to_i | ||
params[:format] = "json" | ||
params[:v] = "1.0" | ||
params[:uids] = session_key["user"]["id"] | ||
params[:session_key] = session_key["renren_token"]["session_key"] | ||
params[:sig] = Digest::MD5.hexdigest(params.map {|k,v| "#{k}=#{v}"}.sort.join("") + client.secret) | ||
params | ||
end | ||
|
||
def session_key | ||
@session_key ||= MultiJson.decode(@access_token.get('/renren_api/session_key')) | ||
end | ||
|
||
def request_phase | ||
options[:scope] ||= "publish_feed" | ||
super | ||
end | ||
|
||
def build_access_token | ||
if renren_session.nil? || renrensession.empty? | ||
super | ||
else | ||
@access_token = ::OAuth2::AccessToken.new(client, renren_session['access_token']) | ||
end | ||
end | ||
|
||
def renren_session | ||
session_cookie = request.cookies["rrs_#{client.id}"] | ||
if session_cookie | ||
@renren_session ||= Rack::Utils.parse_query(request.cookies["rrs_#{client.id}"].gsub('"', '')) | ||
else | ||
nil | ||
end | ||
end | ||
|
||
def user_info | ||
{ | ||
'name' => user_data["name"], | ||
'image' => user_data["tinyurl"] | ||
} | ||
end | ||
|
||
def auth_hash | ||
OmniAuth::Utils.deep_merge(super, { | ||
'uid' => user_data['uid'], | ||
'user_info' => user_info, | ||
'extra' => {'user_hash' => user_data} | ||
}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 |
Oops, something went wrong.