oa-basic 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/CHANGELOG.rdoc ADDED
File without changes
data/LICENSE.rdoc ADDED
File without changes
data/README.rdoc ADDED
File without changes
@@ -0,0 +1,5 @@
1
+ require 'omniauth/core'
2
+ require 'omniauth/strategies/http_basic'
3
+
4
+ require 'omniauth/strategies/campfire'
5
+ require 'omniauth/strategies/basecamp'
@@ -0,0 +1,53 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class Basecamp < HttpBasic
4
+ def initialize(app)
5
+ require 'json'
6
+ super(app, :basecamp, nil)
7
+ end
8
+
9
+ def endpoint
10
+ "http://#{request.params['user']}:#{request.params['password']}@#{request.params['subdomain']}.basecamphq.com/me.xml"
11
+ end
12
+
13
+ def perform_authentication(endpoint)
14
+ super(endpoint) rescue super(endpoint.sub('http','https'))
15
+ end
16
+
17
+ def auth_hash
18
+ doc = Nokogiri::XML.parse(@response.body)
19
+ OmniAuth::Utils.deep_merge(super, {
20
+ 'uid' => doc.xpath('person/id').text,
21
+ 'user_info' => user_info(doc),
22
+ 'credentials' => {
23
+ 'token' => doc.xpath('person/token').text
24
+ }
25
+ })
26
+ end
27
+
28
+ def user_info(doc)
29
+ hash = {
30
+ 'nickname' => request.params['user'],
31
+ 'first_name' => doc.xpath('person/first-name').text,
32
+ 'last_name' => doc.xpath('person/last-name').text,
33
+ 'email' => doc.xpath('person/email-address').text,
34
+ 'image' => doc.xpath('person/avatar-url').text
35
+ }
36
+
37
+ hash['name'] = [hash['first_name'], hash['last_name']].join(' ').strip
38
+
39
+ hash.delete('image') if hash['image'].include?('missing/avatar.png')
40
+
41
+ hash
42
+ end
43
+
44
+ def get_credentials
45
+ OmniAuth::Form.build('Basecamp Authentication') do
46
+ text_field 'Subdomain', 'subdomain'
47
+ text_field 'Username', 'user'
48
+ password_field 'Password', 'password'
49
+ end.to_response
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,45 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class Campfire < HttpBasic
4
+ def initialize(app)
5
+ require 'json'
6
+ super(app, :campfire, nil)
7
+ end
8
+
9
+ def endpoint
10
+ "http://#{request.params['user']}:#{request.params['password']}@#{request.params['subdomain']}.campfirenow.com/users/me.json"
11
+ end
12
+
13
+ def perform_authentication(endpoint)
14
+ super(endpoint) rescue super(endpoint.sub('http','https'))
15
+ end
16
+
17
+ def auth_hash
18
+ user_hash = JSON.parse(@response.body)['user']
19
+ OmniAuth::Utils.deep_merge(super, {
20
+ 'uid' => user_hash['id'],
21
+ 'user_info' => user_info(user_hash),
22
+ 'credentials' => {
23
+ 'token' => user_hash['api_auth_token']
24
+ }
25
+ })
26
+ end
27
+
28
+ def user_info(hash)
29
+ {
30
+ 'nickname' => request.params['user'],
31
+ 'name' => hash['name'],
32
+ 'email' => hash['email_address']
33
+ }
34
+ end
35
+
36
+ def get_credentials
37
+ OmniAuth::Form.build('Campfire Authentication') do
38
+ text_field 'Subdomain', 'subdomain'
39
+ text_field 'Username', 'user'
40
+ password_field 'Password', 'password'
41
+ end.to_response
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ # Gowalla's API isn't authenticated yet
2
+ # so this won't actually work at all it
3
+ # turns out.
4
+
5
+ # module OmniAuth
6
+ # module Strategies
7
+ # class Gowalla < OmniAuth::Strategies::HttpBasic #:nodoc:
8
+ # def initialize(app, api_key)
9
+ # super(app, :gowalla, nil, {'X-Gowalla-API-Key' => api_key, 'Accept' => 'application/json'})
10
+ # end
11
+ #
12
+ # def endpoint
13
+ # "http://#{request[:username]}:#{request[:password]}@api.gowalla.com/users/#{request[:username]}"
14
+ # end
15
+ # end
16
+ # end
17
+ # end
@@ -0,0 +1,56 @@
1
+ require 'restclient'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class HttpBasic
6
+ include OmniAuth::Strategy
7
+
8
+ def initialize(app, name, endpoint, headers = {})
9
+ super
10
+ @endpoint = endpoint
11
+ @request_headers = headers
12
+ end
13
+
14
+ attr_reader :endpoint, :request_headers
15
+
16
+ def request_phase
17
+ if env['REQUEST_METHOD'] == 'GET'
18
+ get_credentials
19
+ else
20
+ perform
21
+ end
22
+ end
23
+
24
+ def title
25
+ name.split('_').map{|s| s.capitalize}.join(' ')
26
+ end
27
+
28
+ def get_credentials
29
+ OmniAuth::Form.build(title) do
30
+ text_field 'Username', 'username'
31
+ password_field 'Password', 'password'
32
+ end.to_response
33
+ end
34
+
35
+ def perform
36
+ @response = perform_authentication(endpoint)
37
+ request.POST['auth'] = auth_hash
38
+ @env['REQUEST_METHOD'] = 'GET'
39
+ @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"
40
+
41
+ @app.call(@env)
42
+ rescue RestClient::Request::Unauthorized
43
+ fail!(:invalid_credentials)
44
+ end
45
+
46
+ def perform_authentication(uri, headers = request_headers)
47
+ RestClient.get(uri, headers)
48
+ end
49
+
50
+ def callback_phase
51
+ fail!(:invalid_credentials)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-basic
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
10
+ platform: ruby
11
+ authors:
12
+ - Michael Bleigh
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-01 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
+ - 3
31
+ version: 0.0.3
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: restclient
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: rspec
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 2
56
+ - 9
57
+ version: 1.2.9
58
+ type: :development
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: webmock
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :development
71
+ version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ name: rack-test
74
+ prerelease: false
75
+ requirement: &id005 !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ type: :development
83
+ version_requirements: *id005
84
+ - !ruby/object:Gem::Dependency
85
+ name: mg
86
+ prerelease: false
87
+ requirement: &id006 !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ type: :development
95
+ version_requirements: *id006
96
+ description: HTTP Basic strategies for OmniAuth.
97
+ email: michael@intridea.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files: []
103
+
104
+ files:
105
+ - lib/omniauth/basic.rb
106
+ - lib/omniauth/strategies/basecamp.rb
107
+ - lib/omniauth/strategies/campfire.rb
108
+ - lib/omniauth/strategies/gowalla.rb
109
+ - lib/omniauth/strategies/http_basic.rb
110
+ - README.rdoc
111
+ - LICENSE.rdoc
112
+ - CHANGELOG.rdoc
113
+ has_rdoc: true
114
+ homepage: http://github.com/intridea/omniauth
115
+ licenses: []
116
+
117
+ post_install_message:
118
+ rdoc_options: []
119
+
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project:
139
+ rubygems_version: 1.3.6
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: HTTP Basic strategies for OmniAuth.
143
+ test_files: []
144
+