omniauth-renren 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-renren.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = omniauth-renren
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Scott Ballantyne, Transi.st
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining
20
+ a copy of this software and associated documentation files (the
21
+ "Software"), to deal in the Software without restriction, including
22
+ without limitation the rights to use, copy, modify, merge, publish,
23
+ distribute, sublicense, and/or sell copies of the Software, and to
24
+ permit persons to whom the Software is furnished to do so, subject to
25
+ the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be
28
+ included in all copies or substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,78 @@
1
+ # lots of stuff taken from https://github.com/yzhang/omniauth/commit/eafc5ff8115bcc7d62c461d4774658979dd0a48e
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Renren < OmniAuth::Strategies::OAuth2
8
+ option :client_options, {
9
+ :authorize_url => 'http://graph.renren.com/oauth/authorize',
10
+ :token_url => 'http://graph.renren.com/oauth/token',
11
+ }
12
+ def request_phase
13
+ super
14
+ end
15
+
16
+ uid { raw_info['uid'] }
17
+
18
+ info do
19
+ {
20
+ "uid" => raw_info["uid"],
21
+ "gender"=> (raw_info['gender'] == '0' ? 'Male' : 'Female'),
22
+ "image"=>raw_info['logo50'],
23
+ 'name' => raw_info['name'],
24
+ 'urls' => {
25
+ 'Kaixin' => "http://www.kaixin001.com/"
26
+ }
27
+ }
28
+ end
29
+
30
+ def signed_params
31
+ params = {}
32
+ params[:api_key] = client.id
33
+ params[:method] = 'users.getInfo'
34
+ params[:call_id] = Time.now.to_i
35
+ params[:format] = 'json'
36
+ params[:v] = '1.0'
37
+ params[:uids] = session_key['user']['id']
38
+ params[:session_key] = session_key['renren_token']['session_key']
39
+ params[:sig] = Digest::MD5.hexdigest(params.map{|k,v| "#{k}=#{v}"}.sort.join + client.secret)
40
+ params
41
+ end
42
+
43
+ def session_key
44
+ @session_key ||= MultiJson.decode(@access_token.get('/renren_api/session_key'))
45
+ end
46
+
47
+ def request_phase
48
+ options[:scope] ||= 'publish_feed'
49
+ super
50
+ end
51
+
52
+ def build_access_token
53
+ if renren_session.nil? || renren_session.empty?
54
+ super
55
+ else
56
+ @access_token = ::OAuth2::AccessToken.new(client, renren_session['access_token'])
57
+ end
58
+ end
59
+
60
+ def renren_session
61
+ session_cookie = request.cookies["rrs_#{client.id}"]
62
+ if session_cookie
63
+ @renren_session ||= Rack::Utils.parse_query(request.cookies["rrs_#{client.id}"].gsub('"', ''))
64
+ else
65
+ nil
66
+ end
67
+ end
68
+
69
+ def raw_info
70
+ @raw_info ||= MultiJson.decode(Net::HTTP.post_form(URI.parse('http://api.renren.com/restserver.do'), signed_params).body)[0]
71
+ puts @raw_info.inspect
72
+ @raw_info
73
+ rescue ::Errno::ETIMEDOUT
74
+ raise ::Timeout::Error
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Renren
3
+ VERSION = "1.0.0.rc2"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-renren/version"
2
+ require 'omniauth/strategies/renren'
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-renren/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-renren"
7
+ s.version = Omniauth::Renren::VERSION
8
+ s.authors = ["Scott Ballantyne"]
9
+ s.email = ["ussballantyne@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{an omniauth strategy for renren}
12
+ s.description = %q{an omniauth strategy for renren}
13
+
14
+ s.rubyforge_project = "omniauth-renren"
15
+ s.add_dependency 'omniauth', '~> 1.0.0.rc2'
16
+ s.add_dependency 'omniauth-oauth2', '~> 1.0.0.rc2'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ # specify any dependencies here; for example:
24
+ # s.add_development_dependency "rspec"
25
+ # s.add_runtime_dependency "rest-client"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-renren
3
+ version: !ruby/object:Gem::Version
4
+ hash: 977940575
5
+ prerelease: true
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ - rc2
11
+ version: 1.0.0.rc2
12
+ platform: ruby
13
+ authors:
14
+ - Scott Ballantyne
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-11-04 00:00:00 +08:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: omniauth
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 977940575
31
+ segments:
32
+ - 1
33
+ - 0
34
+ - 0
35
+ - rc2
36
+ version: 1.0.0.rc2
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: omniauth-oauth2
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ hash: 977940575
48
+ segments:
49
+ - 1
50
+ - 0
51
+ - 0
52
+ - rc2
53
+ version: 1.0.0.rc2
54
+ type: :runtime
55
+ version_requirements: *id002
56
+ description: an omniauth strategy for renren
57
+ email:
58
+ - ussballantyne@gmail.com
59
+ executables: []
60
+
61
+ extensions: []
62
+
63
+ extra_rdoc_files: []
64
+
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - README.rdoc
69
+ - Rakefile
70
+ - lib/omniauth-renren.rb
71
+ - lib/omniauth-renren/version.rb
72
+ - lib/omniauth/strategies/renren.rb
73
+ - omniauth-renren.gemspec
74
+ has_rdoc: true
75
+ homepage: ""
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">"
96
+ - !ruby/object:Gem::Version
97
+ hash: 25
98
+ segments:
99
+ - 1
100
+ - 3
101
+ - 1
102
+ version: 1.3.1
103
+ requirements: []
104
+
105
+ rubyforge_project: omniauth-renren
106
+ rubygems_version: 1.3.7
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: an omniauth strategy for renren
110
+ test_files: []
111
+