http-token-auth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/http-token-auth.gemspec +24 -0
- data/lib/http/token_auth.rb +3 -0
- data/lib/http/token_auth/authorization_header_parser.rb +61 -0
- data/lib/http/token_auth/credentials.rb +67 -0
- data/lib/http/token_auth/version.rb +5 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0e4b07956136703ffbbaa110ee01175dd85eefb
|
4
|
+
data.tar.gz: f2a78c070b0d34a32da75a729343e035845e2f22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5aab0c83f14dab2776ccff79945d34320a425373e4102985b69e0b308cde93e7ef6abeb2dd88bff265a92e157f1ea5bdcf69bc049ccab5e92f0a08ddf363d10
|
7
|
+
data.tar.gz: aecf139625ed96dc4fd3a13f1e0fb7caea1ec367e553b84bb0ca0a14c5ad9ea43b9195cce8d3c1b1de3e141ea71d03217fbabf1452c4b38c28ecaf55ea5237cf
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Felipe Dornelas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'http/token_auth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'http-token-auth'
|
8
|
+
gem.version = HTTP::TokenAuth::VERSION
|
9
|
+
gem.authors = ['Felipe Dornelas']
|
10
|
+
gem.email = ['m@felipedornelas.com']
|
11
|
+
gem.description = %s(Ruby gem to handle the HTTP Token Access Authentication.)
|
12
|
+
gem.summary = %s(Ruby gem to handle the HTTP Token Access Authentication.)
|
13
|
+
gem.homepage = 'https://github.com/felipead/http-token-auth'
|
14
|
+
|
15
|
+
# rubocop:disable Style/SpecialGlobalVars
|
16
|
+
gem.files = `git ls-files bin lib http-token-auth.gemspec LICENSE.txt`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
gem.license = 'MIT'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
gem.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module HTTP
|
2
|
+
module TokenAuth
|
3
|
+
def self.parse_authorization_header(header)
|
4
|
+
parser = AuthorizationHeaderParser.new
|
5
|
+
parser.parse(header)
|
6
|
+
end
|
7
|
+
|
8
|
+
class AuthorizationHeaderParsingError < StandardError
|
9
|
+
def initialize(submessage)
|
10
|
+
super(%(Error parsing "Authorization" HTTP header with token scheme: #{submessage}))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class AuthorizationHeaderParser
|
15
|
+
def parse(header)
|
16
|
+
scheme, attributes = split(header)
|
17
|
+
raise AuthorizationHeaderParsingError,
|
18
|
+
'Header has no attributes' if attributes.nil?
|
19
|
+
raise AuthorizationHeaderParsingError,
|
20
|
+
%(Invalid scheme "#{scheme}") unless scheme == 'Token'
|
21
|
+
build_credentials parse_attributes(attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def split(header)
|
25
|
+
header.split(' ', 2)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_attributes(string)
|
29
|
+
attributes = {}
|
30
|
+
string.scan(/(\w+)="([^"]*)"/).each do |group|
|
31
|
+
attributes[group[0].to_sym] = group[1]
|
32
|
+
end
|
33
|
+
attributes
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_credentials(attributes)
|
37
|
+
Credentials.new token: attributes[:token],
|
38
|
+
coverage: parse_coverage(attributes[:coverage]),
|
39
|
+
nonce: attributes[:nonce],
|
40
|
+
auth: attributes[:auth],
|
41
|
+
timestamp: parse_timestamp(attributes[:timestamp])
|
42
|
+
rescue MissingCredentialsArgumentError => e
|
43
|
+
raise AuthorizationHeaderParsingError, e.message
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_coverage(coverage)
|
47
|
+
return nil if coverage.nil? || coverage.empty?
|
48
|
+
case coverage
|
49
|
+
when 'none' then nil
|
50
|
+
when 'base' then :base
|
51
|
+
when 'base+body-sha-256' then :base_body_sha_256
|
52
|
+
else raise AuthorizationHeaderParsingError, %(Invalid coverage "#{coverage}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_timestamp(timestamp)
|
57
|
+
timestamp.nil? ? nil : timestamp.to_i
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module HTTP
|
2
|
+
module TokenAuth
|
3
|
+
class MissingCredentialsArgumentError < StandardError
|
4
|
+
def initialize(argument_name)
|
5
|
+
super(%(Invalid token credentials: "#{argument_name}" is missing))
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Credentials
|
10
|
+
attr_reader :token, :coverage, :nonce, :auth, :timestamp
|
11
|
+
|
12
|
+
def initialize(token:, coverage: nil, nonce: nil, auth: nil, timestamp: nil)
|
13
|
+
@token = token
|
14
|
+
@coverage = coverage
|
15
|
+
@nonce = nonce
|
16
|
+
@auth = auth
|
17
|
+
@timestamp = timestamp
|
18
|
+
validate_itself
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_header
|
22
|
+
attributes = []
|
23
|
+
attributes << %(token="#{@token}")
|
24
|
+
unless coverage.nil?
|
25
|
+
attributes << %(coverage="#{coverage_name}")
|
26
|
+
attributes << %(nonce="#{@nonce}")
|
27
|
+
attributes << %(auth="#{@auth}")
|
28
|
+
attributes << %(timestamp="#{@timestamp}")
|
29
|
+
end
|
30
|
+
"Token #{attributes.join(', ')}"
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def validate_itself
|
36
|
+
must_have_token
|
37
|
+
return if @coverage.nil?
|
38
|
+
must_have_nonce
|
39
|
+
must_have_auth
|
40
|
+
must_have_timestamp
|
41
|
+
end
|
42
|
+
|
43
|
+
def must_have_token
|
44
|
+
raise MissingCredentialsArgumentError, 'token' if @token.nil? || @token.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
def must_have_nonce
|
48
|
+
raise MissingCredentialsArgumentError, 'nonce' if @nonce.nil? || @nonce.empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def must_have_auth
|
52
|
+
raise MissingCredentialsArgumentError, 'auth' if @auth.nil? || @auth.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def must_have_timestamp
|
56
|
+
raise MissingCredentialsArgumentError, 'timestamp' if @timestamp.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
def coverage_name
|
60
|
+
case @coverage
|
61
|
+
when :base then 'base'
|
62
|
+
when :base_body_sha_256 then 'base+body-sha-256'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-token-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Felipe Dornelas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Ruby gem to handle the HTTP Token Access Authentication.
|
42
|
+
email:
|
43
|
+
- m@felipedornelas.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE.txt
|
49
|
+
- http-token-auth.gemspec
|
50
|
+
- lib/http/token_auth.rb
|
51
|
+
- lib/http/token_auth/authorization_header_parser.rb
|
52
|
+
- lib/http/token_auth/credentials.rb
|
53
|
+
- lib/http/token_auth/version.rb
|
54
|
+
homepage: https://github.com/felipead/http-token-auth
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Ruby gem to handle the HTTP Token Access Authentication.
|
78
|
+
test_files: []
|