cow_auth 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b61a286553d8f86105a6f285edea7f2cdb2834be2083dc6c4cb84cbbec44912
4
- data.tar.gz: fe7353598f52d7249a77877772bf41257ffa350c6ea1b78ec3a75b50054dbaf4
3
+ metadata.gz: 1455b64dcd0206bf8ffd9a4539f4de942952ede5dad80c60b0f86186814735fc
4
+ data.tar.gz: fc0e8de3a619e761b9fcdc525622d8056f20f939e60592064ada6f76adbcf9a3
5
5
  SHA512:
6
- metadata.gz: 2783eea610cc94b85cbbf10b54ae242be3b7828617daf48aa04372ffcffdfcb9cd15ab7a30c7cefc7dace3148d5789d74870424ae0b25f577a344b57f1e9203b
7
- data.tar.gz: 5e6baa8f5838abc4cbd4518dbc2ce73d50f771c6e04daf99a3b5a3d8d95455b359c642c0fcbc2d0e850b882cccf70c5728cb00da9ddf7af48bd0f0ed4976b057
6
+ metadata.gz: 5d2fc711916cb332f6279cee78459af32a0610264a95ab4899db92d693d6083acbef67491c2ed296e102f8423b5e0ebd50cabbc749ce3cd61eaa06cdd4bed0d4
7
+ data.tar.gz: 964cf902670e4f7298b9ba2593e675d7fd00699424c79bc38e6cafb67072b39bb5462e336e1408dbaa7868ab1a70a086952c54220a874cfcf858949610b3d8db
data/Gemfile.lock CHANGED
@@ -1,57 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cow_auth (0.5.2)
5
- actionpack (~> 5.1)
4
+ cow_auth (0.5.3)
6
5
  activesupport (~> 5.1)
7
6
  scrypt (~> 3.0)
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
- actionpack (5.1.4)
13
- actionview (= 5.1.4)
14
- activesupport (= 5.1.4)
15
- rack (~> 2.0)
16
- rack-test (>= 0.6.3)
17
- rails-dom-testing (~> 2.0)
18
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
- actionview (5.1.4)
20
- activesupport (= 5.1.4)
21
- builder (~> 3.1)
22
- erubi (~> 1.4)
23
- rails-dom-testing (~> 2.0)
24
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
11
  activesupport (5.1.4)
26
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
27
13
  i18n (~> 0.7)
28
14
  minitest (~> 5.1)
29
15
  tzinfo (~> 1.1)
30
- builder (3.2.3)
31
16
  concurrent-ruby (1.0.5)
32
- crass (1.0.3)
33
- erubi (1.7.0)
34
17
  ffi (1.9.18)
35
18
  ffi-compiler (1.0.1)
36
19
  ffi (>= 1.0.0)
37
20
  rake
38
21
  i18n (0.9.1)
39
22
  concurrent-ruby (~> 1.0)
40
- loofah (2.1.1)
41
- crass (~> 1.0.2)
42
- nokogiri (>= 1.5.9)
43
- mini_portile2 (2.3.0)
44
23
  minitest (5.11.1)
45
- nokogiri (1.8.1)
46
- mini_portile2 (~> 2.3.0)
47
- rack (2.0.3)
48
- rack-test (0.8.2)
49
- rack (>= 1.0, < 3)
50
- rails-dom-testing (2.0.3)
51
- activesupport (>= 4.2.0)
52
- nokogiri (>= 1.6)
53
- rails-html-sanitizer (1.0.3)
54
- loofah (~> 2.0)
55
24
  rake (12.3.0)
56
25
  scrypt (3.0.5)
57
26
  ffi-compiler (>= 1.0, < 2.0)
data/cow_auth.gemspec CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'bundler', '~> 1.16'
27
27
  spec.add_development_dependency 'rake', '~> 12.3'
28
28
  spec.add_development_dependency 'minitest', '~> 5.11'
29
- spec.add_runtime_dependency 'actionpack', '~> 5.1'
30
29
  spec.add_runtime_dependency 'activesupport', '~> 5.1'
31
30
  spec.add_runtime_dependency 'scrypt', '~> 3.0'
32
31
  end
@@ -4,17 +4,30 @@ module CowAuth
4
4
  module TokenAuth
5
5
  module AuthenticateRequest
6
6
  extend ActiveSupport::Concern
7
- include ActionController::HttpAuthentication::Token::ControllerMethods
8
7
 
9
8
  private
10
9
 
10
+ SID_KEY = 'sid='
11
+ TOKEN_KEY = 'token='
12
+ AUTHORIZATION_REGEX = /^(Token|Bearer)\s*/
13
+ AUTHORIZATION_DELIMITERS = /(?:,|;|\t+)/
14
+
11
15
  def authenticate_user
12
- authenticate_or_request_with_http_token do |token, options|
13
- user = authentication_class.find_by(sid: options[:sid])
14
- @current_user = user.try(:authenticate_with_token, token) ? user : nil
15
- raise CowAuth::NotAuthenticatedError.new('User not authenticated.') if @current_user.blank?
16
- return true
16
+ sid, auth_token = extract_credentials(request.authorization)
17
+ if sid.present? && auth_token.present?
18
+ user = authentication_class.find_by(sid: sid)
19
+ @current_user = user.try(:authenticate_with_token, auth_token) ? user : nil
20
+ return true if @current_user.present?
17
21
  end
22
+ raise CowAuth::NotAuthenticatedError.new('User not authenticated.')
23
+ end
24
+
25
+ def extract_credentials(authorization_header)
26
+ return nil if authorization_header.blank? || !(authorization_header =~ /\A#{AUTHORIZATION_REGEX}/)
27
+ params = authorization_header.sub(AUTHORIZATION_REGEX, '').split(/\s*#{AUTHORIZATION_DELIMITERS}\s*/)
28
+ sid = params[1].sub(SID_KEY, '') if params[1] =~ /\A#{SID_KEY}/
29
+ auth_token = params[0].sub(TOKEN_KEY, '') if params[0] =~ /\A#{TOKEN_KEY}/
30
+ return sid, auth_token
18
31
  end
19
32
 
20
33
  def current_user
@@ -1,3 +1,3 @@
1
1
  module CowAuth
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cow_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickey Cowden
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.11'
55
- - !ruby/object:Gem::Dependency
56
- name: actionpack
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.1'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.1'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: activesupport
71
57
  requirement: !ruby/object:Gem::Requirement