omniauth-http-basic 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'http://rubygems.org'
2
+
3
+ platforms :jruby do
4
+ gem 'jruby-openssl', '~> 0.7'
5
+ end
6
+
7
+ gemspec
8
+
9
+ group :development, :test do
10
+ gem 'guard'
11
+ gem 'guard-rspec'
12
+ gem 'guard-bundler'
13
+ gem 'growl'
14
+ gem 'rb-fsevent'
15
+ end
@@ -0,0 +1,11 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+
8
+ guard 'bundler' do
9
+ watch('Gemfile')
10
+ watch(/^.+\.gemspec/)
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011-2012 Jan Xie <jan.h.xie@gmail.com>
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.
@@ -0,0 +1,22 @@
1
+ = OmniAuth::HttpBasic
2
+
3
+ OmniAuth stratgies for APIs that have HTTP Basic authentication.
4
+
5
+ This strategy is intended for developer's convinience, it will NOT set any uid or auth_hash data like a user strategy. So in most cases you need to create your own strategy by subclassing this strategy, and set uid and auth_hash there.
6
+
7
+ == Use it by subclass
8
+
9
+ Check https://github.com/janx/omniauth-broadworks for example.
10
+
11
+ ==
12
+
13
+ Install manually or using Bundler:
14
+
15
+ gem 'omniauth-http-basic'
16
+
17
+ Add :httpbasic provider to omniauth builder:
18
+
19
+ use OmniAuth::Builder do
20
+ provider :httpbasic, "https://example.com/user_info"
21
+ # provider ...
22
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs'
7
+ task :default => :spec
8
+
9
+ desc 'Run specs'
10
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,2 @@
1
+ require 'omniauth-http-basic/version'
2
+ require 'omniauth/strategies/http_basic'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module HttpBasic
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require 'omniauth'
2
+ require 'net/http'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class HttpBasic
7
+ include OmniAuth::Strategy
8
+
9
+ args [:endpoint]
10
+
11
+ option :title, "Http Basic"
12
+ option :headers, {}
13
+
14
+ def request_phase
15
+ OmniAuth::Form.build(:title => options.title, :url => callback_path) do
16
+ text_field 'Username', 'username'
17
+ password_field 'Password', 'password'
18
+ end.to_response
19
+ end
20
+
21
+ def callback_phase
22
+ return fail!(:invalid_credentials) if !authentication_response
23
+ return fail!(:invalid_credentials) if authentication_response.code.to_i >= 400
24
+ super
25
+ end
26
+
27
+ protected
28
+
29
+ # by default we use static uri. If dynamic uri is required, override
30
+ # this method.
31
+ def api_uri
32
+ options.endpoint
33
+ end
34
+
35
+ def username
36
+ request['username']
37
+ end
38
+
39
+ def password
40
+ request['password']
41
+ end
42
+
43
+ def authentication_response
44
+ unless @authentication_response
45
+ return unless username && password
46
+
47
+ uri = URI(api_uri)
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ if uri.scheme == 'https'
50
+ http.use_ssl = true
51
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52
+ end
53
+
54
+ req = Net::HTTP::Get.new(uri.request_uri)
55
+ req.basic_auth username, password
56
+ @authentication_response = http.request(req)
57
+ end
58
+
59
+ @authentication_response
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/omniauth-http-basic/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'omniauth', '~> 1.0'
6
+ gem.add_dependency 'faraday', '~> 0.7.5'
7
+
8
+ gem.add_development_dependency 'rspec', '~> 2.7'
9
+ gem.add_development_dependency 'rack-test'
10
+ gem.add_development_dependency 'simplecov'
11
+ gem.add_development_dependency 'webmock'
12
+ gem.add_development_dependency 'yard'
13
+
14
+ gem.authors = ['Jan Xie']
15
+ gem.email = ['jan.h.xie@gmail.com']
16
+ gem.description = %q{HTTP Basic strategies for OmniAuth.}
17
+ gem.summary = gem.description
18
+ gem.homepage = 'http://github.com/janx/omniauth-http-basic'
19
+
20
+ gem.name = 'omniauth-http-basic'
21
+ gem.require_paths = ['lib']
22
+ gem.files = `git ls-files`.split("\n")
23
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ gem.version = OmniAuth::HttpBasic::VERSION
25
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OmniAuth::Strategies::HttpBasic do
4
+ def app; lambda {|env| [200, {}, ["Hello HttpBasic!"]]}; end
5
+
6
+ let(:fresh_strategy) { Class.new OmniAuth::Strategies::HttpBasic }
7
+ subject { fresh_strategy }
8
+
9
+ it 'should be initialized with authentication endpoint' do
10
+ instance = subject.new(app, "http://www.example.com/httpauth")
11
+ instance.options.endpoint.should == "http://www.example.com/httpauth"
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+ require 'rspec'
7
+ require 'rack/test'
8
+ require 'webmock/rspec'
9
+ require 'omniauth'
10
+ require 'omniauth-http-basic'
11
+
12
+ RSpec.configure do |config|
13
+ config.include WebMock::API
14
+ config.include Rack::Test::Methods
15
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
16
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-http-basic
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jan Xie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-21 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &15528320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *15528320
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &15527820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.5
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *15527820
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &15527360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.7'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *15527360
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack-test
49
+ requirement: &15526980 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *15526980
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &15526520 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *15526520
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: &15526100 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *15526100
80
+ - !ruby/object:Gem::Dependency
81
+ name: yard
82
+ requirement: &15525680 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *15525680
91
+ description: HTTP Basic strategies for OmniAuth.
92
+ email:
93
+ - jan.h.xie@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - .gitignore
99
+ - .rspec
100
+ - Gemfile
101
+ - Guardfile
102
+ - LICENSE
103
+ - README.rdoc
104
+ - Rakefile
105
+ - lib/omniauth-http-basic.rb
106
+ - lib/omniauth-http-basic/version.rb
107
+ - lib/omniauth/strategies/http_basic.rb
108
+ - omniauth-http-basic.gemspec
109
+ - spec/omniauth/strategies/http_basic_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: http://github.com/janx/omniauth-http-basic
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 1.8.6
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: HTTP Basic strategies for OmniAuth.
135
+ test_files:
136
+ - spec/omniauth/strategies/http_basic_spec.rb
137
+ - spec/spec_helper.rb
138
+ has_rdoc: