omniauth-xiaonei 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,9 +1,37 @@
1
- = Omniauth-renren
1
+ = Omniauth-xiaonei
2
2
 
3
3
  Omniauth strategy for renren[http://www.renren.com]
4
4
 
5
5
  = Usage
6
6
 
7
+ gem install omniauth-xiaonei
8
+
9
+ 具体用法请参照Omniauth和example文件夹下的client_side.rb:
10
+
11
+ gem install sinatra --no-rdoc --no-ri
12
+ ruby -rubygems client_side.rb
13
+
14
+ 如果出现"forbidden"等问题,有可能是因为Omniauth-oauth2 1.1.0的bug,可以这样解决:
15
+
16
+ # 在Gemfile中加入这一行
17
+ gem "omniauth-oauth2", :git => "git://github.com/lastomato/omniauth-oauth2.git"
18
+ # 然后运行
19
+ bundle install
20
+
21
+ # 或者安装 1.0.2版本的Omniauth-oauth2
22
+ gem install --version "1.0.2" omniauth-oauth2
23
+
24
+ 在config/initializers/omniauth.rb中,可以传入:fields参数,其值为字符串,作用是在认证结束阶段返回用户资料时指定返回的具体内容。
25
+ 可以参见人人的文档:http://wiki.dev.renren.com/wiki/Users.getInfo
26
+
27
+ 下面是可以选的值:
28
+
29
+ "uid,name,sex,star,zidou,vip,birthday,tinyurl,headurl,mainurl,hometown_location,work_history,university_history"
30
+
31
+ 如果不填,那么默认的值为:"uid,name,tinyurl,headhurl,zidou,star"
32
+
33
+ 参数的具体含义请参照人人的文档(如上所示)。
34
+
7
35
  Please refer to Omniauth[https://github.com/intridea/omniauth/] for usage
8
36
 
9
37
  = Thanks
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "sinatra"
4
+ require "omniauth-xiaonei"
5
+ require "multi_json"
6
+
7
+ use Rack::Session::Cookie
8
+
9
+ # set your api_key and api_secret here
10
+ use OmniAuth::Builder do
11
+ provider :xiaonei, API_KEY, API_SECRET
12
+ end
13
+
14
+ # sending request
15
+ get "/" do
16
+ redirect "/auth/xiaonei"
17
+ end
18
+
19
+ # callback phase
20
+ get "/auth/:provider/callback" do
21
+ content_type "application/json"
22
+ begin
23
+ MultiJson.encode(request.env)
24
+ rescue Exception => e
25
+ end
26
+ end
27
+
28
+ # in case of failure
29
+ get "/auth/failure" do
30
+ content_type "application/json"
31
+ MultiJson.encode(request.env)
32
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth/xiaonei"
2
+
@@ -1,74 +1,74 @@
1
- require "faraday"
2
- require "digest/md5"
3
- require "omniauth/strategies/oauth2"
4
-
5
- module OmniAuth
6
- module Strategies
7
- class Renren < OmniAuth::Strategies::OAuth2
8
- option :name, "renren"
9
-
10
- option :client_options, {
11
- :site => "https://graph.renren.com"
12
- }
13
-
14
- option :token_params, {
15
- :grant_type => "authorization_code"
16
- }
17
-
18
- #option :api_url, "http://api.renren.com/restserver.do"
19
-
20
- def request_phase
21
- redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
22
- end
23
-
24
- def raw_info
25
- opts = {
26
- :method => "users.getInfo",
27
- :v => "1.0",
28
- :format => "JSON",
29
- :access_token => access_token.token
30
- }.merge!(fields)
31
- conn = Faraday.new(:url => "http://api.renren.com") do |faraday|
32
- faraday.request :url_encoded
33
- faraday.response :logger
34
- faraday.adapter Faraday.default_adapter
35
- end
36
- @raw_info ||= parse(conn.post("/restserver.do", append_sig(opts)).body).first || {}
37
- end
38
-
39
- uid {
40
- raw_info[:uid.to_s]
41
- }
42
-
43
- info {
44
- (options[:fields] || "name,email_hash,tinyurl,headurl,zidou,star").split(",").inject({}) { |t,v| t[v.to_sym] = raw_info[v];t }
45
- }
46
-
47
- extra {
48
- hash = {}
49
- hash["raw_info"] = raw_info unless skip_info?
50
- prune! hash
51
- }
52
-
53
- private
54
- def append_sig(opts = {})
55
- opts.merge!({ :sig => Digest::MD5.hexdigest(opts.inject([]) { |t, v| t << v.join("=") }.sort.join + options.client_secret) })
56
- end
57
-
58
- def fields
59
- options[:fields] ? { :fields => options[:fields] } : {}
60
- end
61
-
62
- def prune!(hash)
63
- hash.delete_if do |_, value|
64
- prune!(value) if value.is_a?(Hash)
65
- value.nil? || (value.respond_to?(:empty?) && value.empty?)
66
- end
67
- end
68
-
69
- def parse(content)
70
- lambda { |body| MultiJson.respond_to?(:adapter) ? MultiJson.load(body) : MultiJson.decode(body) rescue body }.call(content)
71
- end
72
- end
73
- end
1
+ require "faraday"
2
+ require "digest/md5"
3
+ require "omniauth/strategies/oauth2"
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Xiaonei < OmniAuth::Strategies::OAuth2
8
+ option :name, "xiaonei"
9
+
10
+ option :client_options, {
11
+ :site => "https://graph.renren.com"
12
+ }
13
+
14
+ option :token_params, {
15
+ :grant_type => "authorization_code"
16
+ }
17
+
18
+ #option :api_url, "http://api.renren.com/restserver.do"
19
+
20
+ def request_phase
21
+ redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
22
+ end
23
+
24
+ def raw_info
25
+ opts = {
26
+ :method => "users.getInfo",
27
+ :v => "1.0",
28
+ :format => "JSON",
29
+ :access_token => access_token.token
30
+ }.merge!(fields)
31
+ conn = Faraday.new(:url => "http://api.renren.com") do |faraday|
32
+ faraday.request :url_encoded
33
+ faraday.response :logger
34
+ faraday.adapter Faraday.default_adapter
35
+ end
36
+ @raw_info ||= parse(conn.post("/restserver.do", append_sig(opts)).body).first || {}
37
+ end
38
+
39
+ uid {
40
+ raw_info[:uid.to_s]
41
+ }
42
+
43
+ info {
44
+ (options[:fields] || "name,email_hash,tinyurl,headurl,zidou,star").split(",").inject({}) { |t,v| t[v.to_sym] = raw_info[v];t }
45
+ }
46
+
47
+ extra {
48
+ hash = {}
49
+ hash["raw_info"] = raw_info unless skip_info?
50
+ prune! hash
51
+ }
52
+
53
+ private
54
+ def append_sig(opts = {})
55
+ opts.merge!({ :sig => Digest::MD5.hexdigest(opts.inject([]) { |t, v| t << v.join("=") }.sort.join + options.client_secret) })
56
+ end
57
+
58
+ def fields
59
+ options[:fields] ? { :fields => options[:fields] } : {}
60
+ end
61
+
62
+ def prune!(hash)
63
+ hash.delete_if do |_, value|
64
+ prune!(value) if value.is_a?(Hash)
65
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
66
+ end
67
+ end
68
+
69
+ def parse(content)
70
+ lambda { |body| MultiJson.respond_to?(:adapter) ? MultiJson.load(body) : MultiJson.decode(body) rescue body }.call(content)
71
+ end
72
+ end
73
+ end
74
74
  end
@@ -0,0 +1,2 @@
1
+ require "omniauth/strategies/xiaonei"
2
+ require "omniauth/xiaonei/version"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Xiaonei
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
@@ -1,17 +1,17 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "omniauth/renren/version"
3
+ require "omniauth/xiaonei/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "omniauth-xiaonei"
7
- s.version = Omniauth::Renren::VERSION
7
+ s.version = Omniauth::Xiaonei::VERSION
8
8
  s.authors = ["Jie Fan"]
9
9
  s.email = ["ustc.flyingfox@gmail.com"]
10
10
  s.homepage = "https://github.com/lastomato/omniauth-xiaonei"
11
- s.summary = %q{Omniauth strategy for Renren}
12
- s.description = %q{Omniauth strategy for Renren}
11
+ s.summary = %q{ Omniauth strategy for Renren (Previous Xiaonei) }
12
+ s.description = %q{ Omniauth strategy for Renren }
13
13
 
14
- s.rubyforge_project = "omniauth-renren"
14
+ s.rubyforge_project = "omniauth-xiaonei"
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-xiaonei
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-30 00:00:00.000000000 Z
12
+ date: 2012-08-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth2
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: Omniauth strategy for Renren
46
+ description: ! ' Omniauth strategy for Renren '
47
47
  email:
48
48
  - ustc.flyingfox@gmail.com
49
49
  executables: []
@@ -54,10 +54,11 @@ files:
54
54
  - Gemfile
55
55
  - README.rdoc
56
56
  - Rakefile
57
- - lib/omniauth-renren.rb
58
- - lib/omniauth/renren.rb
59
- - lib/omniauth/renren/version.rb
60
- - lib/omniauth/strategies/renren.rb
57
+ - example/client_side.rb
58
+ - lib/omniauth-xiaonei.rb
59
+ - lib/omniauth/strategies/xiaonei.rb
60
+ - lib/omniauth/xiaonei.rb
61
+ - lib/omniauth/xiaonei/version.rb
61
62
  - omniauth-renren.gemspec
62
63
  homepage: https://github.com/lastomato/omniauth-xiaonei
63
64
  licenses: []
@@ -78,9 +79,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  - !ruby/object:Gem::Version
79
80
  version: '0'
80
81
  requirements: []
81
- rubyforge_project: omniauth-renren
82
+ rubyforge_project: omniauth-xiaonei
82
83
  rubygems_version: 1.8.24
83
84
  signing_key:
84
85
  specification_version: 3
85
- summary: Omniauth strategy for Renren
86
+ summary: Omniauth strategy for Renren (Previous Xiaonei)
86
87
  test_files: []
@@ -1,2 +0,0 @@
1
- require "omniauth/renren"
2
-
@@ -1,2 +0,0 @@
1
- require "omniauth/strategies/renren"
2
- require "omniauth/renren/version"
@@ -1,5 +0,0 @@
1
- module Omniauth
2
- module Renren
3
- VERSION = "0.0.2"
4
- end
5
- end