oa-oauth 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ = Changelog
2
+
3
+ == 0.0.1
4
+
5
+ * Initial release!
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Michael Bleigh, Intridea Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
File without changes
@@ -0,0 +1,10 @@
1
+ require 'oauth'
2
+ require 'oauth2'
3
+
4
+ require 'omniauth/core'
5
+ require 'omniauth/strategies/oauth'
6
+ require 'omniauth/strategies/twitter'
7
+ require 'omniauth/strategies/linked_in'
8
+ require 'omniauth/strategies/oauth2'
9
+ require 'omniauth/strategies/facebook'
10
+ require 'omniauth/strategies/github'
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ #
6
+ # Authenticate to Facebook utilizing OAuth 2.0 and retrieve
7
+ # basic user information.
8
+ #
9
+ # Usage:
10
+ #
11
+ # use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret'
12
+ #
13
+ # Options:
14
+ #
15
+ # <tt>:scope</tt> :: Extended permissions such as <tt>email</tt> and <tt>offline_access</tt> (which are the defaults).
16
+ class Facebook < OAuth2
17
+ def initialize(app, app_id, app_secret, options = {})
18
+ options[:site] = 'https://graph.facebook.com/'
19
+ super(app, :facebook, app_id, app_secret, options)
20
+ end
21
+
22
+ def user_data
23
+ @data ||= JSON.parse(@access_token.get('/me'))
24
+ end
25
+
26
+ def request_phase(options = {})
27
+ options[:scope] ||= "email,offline_access"
28
+ super(options)
29
+ end
30
+
31
+ def user_info
32
+ {
33
+ 'nickname' => user_data["link"].split('/').last,
34
+ 'first_name' => user_data["first_name"],
35
+ 'last_name' => user_data["last_name"],
36
+ 'name' => "#{user_data['first_name']} #{user_data['last_name']}",
37
+ 'urls' => {
38
+ 'Facebook' => user_data["link"],
39
+ 'Website' => user_data["website"],
40
+ }
41
+ }
42
+ end
43
+
44
+ def auth_hash
45
+ OmniAuth::Utils.deep_merge(super, {
46
+ 'uid' => user_data['id'],
47
+ 'user_info' => user_info,
48
+ 'extra' => {'user_hash' => user_data}
49
+ })
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class GitHub < OAuth2
6
+ def initialize(app, app_id, app_secret, options = {})
7
+ options[:site] = 'https://github.com/'
8
+ options[:authorize_path] = '/login/oauth/authorize'
9
+ options[:access_token_path] = '/login/oauth/access_token'
10
+ super(app, :github, app_id, app_secret, options)
11
+ end
12
+
13
+ def user_data
14
+ @data ||= JSON.parse(@access_token.get('/api/v2/json/user/show'))['user']
15
+ end
16
+
17
+ def user_info
18
+ {
19
+ 'nickname' => user_data["login"],
20
+ 'email' => user_data['email'],
21
+ 'name' => user_data['name'],
22
+ 'urls' => {
23
+ 'GitHub' => "http://github.com/#{user_data['login']}",
24
+ 'Blog' => user_data["blog"],
25
+ }
26
+ }
27
+ end
28
+
29
+ def auth_hash
30
+ OmniAuth::Utils.deep_merge(super, {
31
+ 'uid' => user_data['id'],
32
+ 'user_info' => user_info,
33
+ 'extra' => {'user_hash' => user_data}
34
+ })
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ require 'omniauth/core'
2
+ require 'omniauth/strategies/oauth'
3
+ require 'nokogiri'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class LinkedIn < OmniAuth::Strategies::OAuth
8
+ def initialize(app, consumer_key, consumer_secret)
9
+ super(app, :linked_in, consumer_key, consumer_secret,
10
+ :site => 'https://api.linkedin.com',
11
+ :request_token_path => '/uas/oauth/requestToken',
12
+ :access_token_path => '/uas/oauth/accessToken',
13
+ :authorize_path => '/uas/oauth/authorize',
14
+ :scheme => :header)
15
+ end
16
+
17
+ def auth_hash
18
+ hash = user_hash(@access_token)
19
+
20
+ OmniAuth::Utils.deep_merge(super, {
21
+ 'uid' => hash.delete('id'),
22
+ 'user_info' => hash
23
+ })
24
+ end
25
+
26
+ def user_hash(access_token)
27
+ person = Nokogiri::XML::Document.parse(@access_token.get('/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location)').body).xpath('person')
28
+
29
+ hash = {
30
+ 'id' => person.xpath('id').text,
31
+ 'first_name' => person.xpath('first-name').text,
32
+ 'last_name' => person.xpath('last-name').text,
33
+ 'location' => person.xpath('location/name').text,
34
+ 'image' => person.xpath('picture-url').text,
35
+ 'description' => person.xpath('headline').text,
36
+ 'urls' => person.css('member-url-resources member-url').inject({}) do |hash,element|
37
+ hash[element.xpath('name').text] = element.xpath('url').text
38
+ hash
39
+ end
40
+ }
41
+
42
+ hash[:name] = "#{hash['first_name']} #{hash['last_name']}"
43
+ hash
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,48 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class OAuth
4
+ include OmniAuth::Strategy
5
+
6
+ def initialize(app, name, consumer_key, consumer_secret, options = {})
7
+ require 'oauth'
8
+ super
9
+ @consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, options)
10
+ end
11
+ attr_reader :name, :consumer
12
+
13
+ def request_phase
14
+ request_token = consumer.get_request_token(:oauth_callback => callback_url)
15
+ (session[:oauth]||={})[name.to_sym] = {:callback_confirmed => request_token.callback_confirmed?, :request_token => request_token.token, :request_secret => request_token.secret}
16
+ r = Rack::Response.new
17
+ r.redirect request_token.authorize_url
18
+ r.finish
19
+ end
20
+
21
+ def callback_phase
22
+ request_token = ::OAuth::RequestToken.new(consumer, session[:oauth][name.to_sym].delete(:request_token), session[:oauth][name.to_sym].delete(:request_secret))
23
+ @access_token = request_token.get_access_token(:oauth_verifier => request.params['oauth_verifier'])
24
+
25
+ request['auth'] = self.auth_hash
26
+
27
+ @app.call(self.env)
28
+ rescue ::OAuth::Unauthorized
29
+ fail!(:invalid_credentials)
30
+ end
31
+
32
+ def auth_hash
33
+ OmniAuth::Utils.deep_merge(super, {
34
+ 'credentials' => {
35
+ 'token' => @access_token.token,
36
+ 'secret' => @access_token.secret
37
+ }, 'extra' => {
38
+ 'access_token' => @access_token
39
+ }
40
+ })
41
+ end
42
+
43
+ def unique_id
44
+ nil
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ require 'cgi'
2
+ require 'uri'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class OAuth2
7
+ include OmniAuth::Strategy
8
+
9
+ def initialize(app, name, client_id, client_secret, options = {})
10
+ super(app, name)
11
+ @options = options
12
+ @client = ::OAuth2::Client.new(client_id, client_secret, options)
13
+ end
14
+
15
+ attr_accessor :client_id, :client_secret, :options
16
+
17
+ def request_phase(options = {})
18
+ redirect @client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
19
+ end
20
+
21
+ def callback_phase
22
+ verifier = request.params['code']
23
+ @access_token = @client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
24
+ super
25
+ rescue ::OAuth2::HTTPError => e
26
+ fail!(:invalid_credentials)
27
+ end
28
+
29
+ def auth_hash
30
+ OmniAuth::Utils.deep_merge(super, {
31
+ 'credentials' => {
32
+ 'token' => @access_token.token
33
+ }
34
+ })
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,48 @@
1
+ require 'omniauth/core'
2
+ require 'omniauth/strategies/oauth'
3
+ require 'json'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ #
8
+ # Authenticate to Twitter via OAuth and retrieve basic
9
+ # user information.
10
+ #
11
+ # Usage:
12
+ #
13
+ # use OmniAuth::Strategies::Twitter, 'consumerkey', 'consumersecret'
14
+ #
15
+ class Twitter < OmniAuth::Strategies::OAuth
16
+ def initialize(app, consumer_key, consumer_secret)
17
+ super(app, :twitter, consumer_key, consumer_secret,
18
+ :site => 'https://api.twitter.com')
19
+ end
20
+
21
+ def auth_hash
22
+ OmniAuth::Utils.deep_merge(super, {
23
+ 'uid' => @access_token.params[:user_id],
24
+ 'user_info' => user_info,
25
+ 'extra' => {'user_hash' => user_hash}
26
+ })
27
+ end
28
+
29
+ def user_info
30
+ user_hash = self.user_hash
31
+
32
+ {
33
+ 'nickname' => user_hash['screen_name'],
34
+ 'name' => user_hash['name'],
35
+ 'location' => user_hash['location'],
36
+ 'image' => user_hash['profile_image_url'],
37
+ 'screen_name' => user_hash['screen_name'],
38
+ 'description' => user_hash['description'],
39
+ 'urls' => {'Website' => user_hash['url']}
40
+ }
41
+ end
42
+
43
+ def user_hash
44
+ @user_hash ||= JSON.parse(@access_token.get('/1/account/verify_credentials.json').body)
45
+ end
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-oauth
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Michael Bleigh
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-29 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oa-core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 0
31
+ version: 0.0.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: oauth
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: oauth2
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :runtime
57
+ version_requirements: *id003
58
+ - !ruby/object:Gem::Dependency
59
+ name: nokogiri
60
+ prerelease: false
61
+ requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ type: :runtime
69
+ version_requirements: *id004
70
+ - !ruby/object:Gem::Dependency
71
+ name: json
72
+ prerelease: false
73
+ requirement: &id005 !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ type: :runtime
81
+ version_requirements: *id005
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ prerelease: false
85
+ requirement: &id006 !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 1
91
+ - 2
92
+ - 9
93
+ version: 1.2.9
94
+ type: :development
95
+ version_requirements: *id006
96
+ - !ruby/object:Gem::Dependency
97
+ name: webmock
98
+ prerelease: false
99
+ requirement: &id007 !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ type: :development
107
+ version_requirements: *id007
108
+ - !ruby/object:Gem::Dependency
109
+ name: rack-test
110
+ prerelease: false
111
+ requirement: &id008 !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ type: :development
119
+ version_requirements: *id008
120
+ - !ruby/object:Gem::Dependency
121
+ name: mg
122
+ prerelease: false
123
+ requirement: &id009 !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ type: :development
131
+ version_requirements: *id009
132
+ description: OAuth strategies for OmniAuth.
133
+ email: michael@intridea.com
134
+ executables: []
135
+
136
+ extensions: []
137
+
138
+ extra_rdoc_files: []
139
+
140
+ files:
141
+ - lib/omniauth/oauth.rb
142
+ - lib/omniauth/strategies/facebook.rb
143
+ - lib/omniauth/strategies/github.rb
144
+ - lib/omniauth/strategies/linked_in.rb
145
+ - lib/omniauth/strategies/oauth.rb
146
+ - lib/omniauth/strategies/oauth2.rb
147
+ - lib/omniauth/strategies/twitter.rb
148
+ - README.rdoc
149
+ - LICENSE.rdoc
150
+ - CHANGELOG.rdoc
151
+ has_rdoc: true
152
+ homepage: http://github.com/intridea/omniauth
153
+ licenses: []
154
+
155
+ post_install_message:
156
+ rdoc_options: []
157
+
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.3.6
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: OAuth strategies for OmniAuth.
181
+ test_files: []
182
+