basic_auth_credentials 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.md +40 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/basic_auth_credentials.rb +12 -0
- data/spec/basic_auth_credentials_spec.rb +34 -0
- data/spec/spec_helper.rb +12 -0
- metadata +142 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.3)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.3)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
redcarpet (2.1.1)
|
16
|
+
rspec (2.10.0)
|
17
|
+
rspec-core (~> 2.10.0)
|
18
|
+
rspec-expectations (~> 2.10.0)
|
19
|
+
rspec-mocks (~> 2.10.0)
|
20
|
+
rspec-core (2.10.1)
|
21
|
+
rspec-expectations (2.10.0)
|
22
|
+
diff-lcs (~> 1.1.3)
|
23
|
+
rspec-mocks (2.10.1)
|
24
|
+
yard (0.8.1)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler
|
31
|
+
jeweler
|
32
|
+
redcarpet
|
33
|
+
rspec
|
34
|
+
yard
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 John Wilger
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# BasicAuthCredentials
|
2
|
+
|
3
|
+
BasicAuthCredentials is a very simple, small object that turns an
|
4
|
+
HTTP basic auth header into a user ID and a password.
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
# these two lines create the same string that an HTTP client (such
|
8
|
+
# as a web browser) would send in the Authorization header.
|
9
|
+
encoded_credentials = Base64.encode64('my_username:my_password')
|
10
|
+
http_header_value = "Basic #{encoded_credentials}"
|
11
|
+
|
12
|
+
# And this is how you would decode that header value. Pretty simple.
|
13
|
+
credentials = BasicAuthCredentials.new(http_header_value)
|
14
|
+
credentials.user_id
|
15
|
+
#=> 'my_username'
|
16
|
+
credentials.password
|
17
|
+
#=> 'my_password'
|
18
|
+
```
|
19
|
+
|
20
|
+
## Contributing to BasicAuthCredentials
|
21
|
+
|
22
|
+
* Check out the latest master to make sure the feature hasn't been
|
23
|
+
implemented or the bug hasn't been fixed yet.
|
24
|
+
* Check out the issue tracker to make sure someone already hasn't
|
25
|
+
requested it and/or contributed it.
|
26
|
+
* Fork the project.
|
27
|
+
* Start a feature/bugfix branch.
|
28
|
+
* Commit and push until you are happy with your contribution.
|
29
|
+
* Make sure to add tests for it. This is important so I don't break it
|
30
|
+
in a future version unintentionally.
|
31
|
+
* Please try not to mess with the Rakefile, version, or history. If you
|
32
|
+
want to have your own version, or is otherwise necessary, that is
|
33
|
+
fine, but please isolate to its own commit so I can cherry-pick around
|
34
|
+
it.
|
35
|
+
|
36
|
+
## Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2012 John Wilger. See LICENSE.txt for
|
39
|
+
further details.
|
40
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "basic_auth_credentials"
|
18
|
+
gem.homepage = "http://github.com/jwilger/basic_auth_credentials"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Decodes HTTP Basic Auth headers}
|
21
|
+
gem.description = %Q{A simple class that takes an HTTP Basic Auth header value and decodes it into a user_id and password}
|
22
|
+
gem.email = "johnwilger@gmail.com"
|
23
|
+
gem.authors = ["John Wilger"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
class BasicAuthCredentials
|
4
|
+
attr_reader :user_id, :password
|
5
|
+
|
6
|
+
def initialize(encoded_credentials)
|
7
|
+
encoded_credentials ||= ''
|
8
|
+
encoded_credentials.sub!(/^Basic\s+/, '')
|
9
|
+
decoded = Base64.decode64(encoded_credentials)
|
10
|
+
@user_id, @password = decoded.split(':', 2)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BasicAuthCredentials do
|
4
|
+
def basic_auth_header(user_id, password)
|
5
|
+
encoded_part = Base64.encode64("#{user_id}:#{password}")
|
6
|
+
"Basic #{encoded_part}"
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'turns an HTTP Basic Auth "Authorization" header into a user_id and a password' do
|
10
|
+
header = basic_auth_header('nobody@example.com', 'This is my password!')
|
11
|
+
credentials = BasicAuthCredentials.new(header)
|
12
|
+
credentials.user_id.should == 'nobody@example.com'
|
13
|
+
credentials.password.should == 'This is my password!'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'gives a nil user_id and password if initialized with nil' do
|
17
|
+
credentials = BasicAuthCredentials.new(nil)
|
18
|
+
credentials.user_id.should == nil
|
19
|
+
credentials.password.should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'gives a nil user_id and password if initialized with a blank string' do
|
23
|
+
credentials = BasicAuthCredentials.new('')
|
24
|
+
credentials.user_id.should == nil
|
25
|
+
credentials.password.should == nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can handle a password that has a colon in it' do
|
29
|
+
header = basic_auth_header('nobody@example.com', 'password:with:colons')
|
30
|
+
credentials = BasicAuthCredentials.new(header)
|
31
|
+
credentials.user_id.should == 'nobody@example.com'
|
32
|
+
credentials.password.should == 'password:with:colons'
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'basic_auth_credentials'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: basic_auth_credentials
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Wilger
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: redcarpet
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: A simple class that takes an HTTP Basic Auth header value and decodes
|
95
|
+
it into a user_id and password
|
96
|
+
email: johnwilger@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
files:
|
103
|
+
- .document
|
104
|
+
- .rspec
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- VERSION
|
111
|
+
- lib/basic_auth_credentials.rb
|
112
|
+
- spec/basic_auth_credentials_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
homepage: http://github.com/jwilger/basic_auth_credentials
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: -4302718667029166781
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.23
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Decodes HTTP Basic Auth headers
|
142
|
+
test_files: []
|