Permalink
Browse files

first commit

  • Loading branch information...
ballantyne committed Oct 30, 2011
0 parents commit d07bbe3c55f76ad79f0c77690d125b2565504c11
Showing with 101 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 Gemfile
  3. 0 README
  4. +1 −0 Rakefile
  5. +2 −0 lib/omniauth-taobao.rb
  6. +5 −0 lib/omniauth-taobao/version.rb
  7. +59 −0 lib/omniauth/strategies/taobao.rb
  8. +26 −0 omniauth-taobao.gemspec
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in omniauth-taobao.gemspec
+gemspec
0 README
No changes.
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
+require "omniauth-taobao/version"
+require "omniauth/strategies/taobao"
@@ -0,0 +1,5 @@
+module Omniauth
+ module Taobao
+ VERSION = "1.0.0.rc2"
+ end
+end
@@ -0,0 +1,59 @@
+# lots of stuff taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth2/taobao.rb
+require 'omniauth-oauth2'
+module OmniAuth
+ module Strategies
+ class Taobao < OmniAuth::Strategies::OAuth2
+ option :client_options, {
+ :authorize_url => 'https://oauth.taobao.com/authorize',
+ :token_url => 'https://oauth.taobao.com/token',
+ }
+ def request_phase
+ options[:state] ||= '1'
+ super
+ end
+
+
+ uid { raw_info['uid'] }
+
+ info do
+ {
+ 'uid' => raw_info['uid'],
+ 'user_info' => raw_info,
+ 'extra' => {
+ 'user_hash' => raw_info,
+ },
+ }
+ end
+
+ def raw_info
+ url = 'http://gw.api.taobao.com/router/rest'
+
+ query_param = {
+ :app_key => client_id,
+
+ # TODO to be moved in options
+ # TODO add more default fields (http://my.open.taobao.com/apidoc/index.htm#categoryId:1-dataStructId:3)
+ :fields => 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,created,last_visit,birthday,type,status,alipay_no,alipay_account,alipay_account,email,consumer_protection,alipay_bind',
+ :format => 'json',
+ :method => 'taobao.user.get',
+ :session => @access_token.token,
+ :sign_method => 'md5',
+ :timestamp => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
+ :v => '2.0'
+ }
+ query_param = generate_sign(query_param)
+ res = Net::HTTP.post_form(URI.parse(url), query_param)
+ @raw_info ||= MultiJson.decode(res.body)['user_get_response']['user']
+ rescue ::Errno::ETIMEDOUT
+ raise ::Timeout::Error
+ end
+
+ def generate_sign(params)
+ # params.sort.collect { |k, v| "#{k}#{v}" }
+ str = client_secret + params.sort {|a,b| "#{a[0]}"<=>"#{b[0]}"}.flatten.join + client_secret
+ params['sign'] = Digest::MD5.hexdigest(str).upcase!
+ params
+ end
+ end
+ end
+end
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "omniauth-taobao/version"
+
+Gem::Specification.new do |s|
+ s.name = "omniauth-taobao"
+ s.version = Omniauth::Taobao::VERSION
+ s.authors = ["Scott Ballantyne"]
+ s.email = ["ussballantyne@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{an omniauth strategy for taobao}
+ s.description = %q{an omniauth strategy for taobao}
+
+ s.rubyforge_project = "omniauth-taobao"
+ s.add_dependency 'omniauth', '~> 1.0.0.rc2'
+ s.add_dependency 'omniauth-oauth2', '~> 1.0.0.rc2'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end

0 comments on commit d07bbe3

Please sign in to comment.