hanami-authentication 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: 9bd3070e629eced5a93c261e5fd540d9e79ffb08
4
- data.tar.gz: aed73bc00b44b5a4bb5850a6c5196818295a0e9c
3
+ metadata.gz: d2a31214eb2008661d6f5e2c152cfc7e8615597d
4
+ data.tar.gz: c8a3bffaf2da59cb1c09db861f7b868cc2e44d39
5
5
  SHA512:
6
- metadata.gz: 67e0f8d355cbfca31744b0b8c45c7d964016d07c3d0bc7ab59ca5952dc413106468adcfca279fbe71aaffca7d9285e146729ad48dfd352f11fe566a3b8f354a2
7
- data.tar.gz: 218e572f9a9ac0d5f15ef1787670c936ff8fd4967fc0390c5e29f39909f13a7f2196b1eb1f823a0bbe701c83cf2ca21f1d5b08e1dfd6c67c132a80a3441eaed3
6
+ metadata.gz: e3ae35f3e5640d99b3ffc54c081a693f8a8087159395560213848a6270738da7af2d19da110eb536f8c90e4637c760078fc2eee2e8c3ccb9ee3655c2f2bb9c7d
7
+ data.tar.gz: 12a9a048158e62ca9ccb29322846b7b6f0bf24d91d43bf6317ae55803760d6ab182153722527067924b62f2b417e81cf106d9c6d201cdb2dc80900136e5e307a
@@ -67,9 +67,9 @@ module Hanami
67
67
  include Utils::ClassAttribute
68
68
 
69
69
  class_attribute :after_session_expired_callbacks
70
- self.after_session_expired_callbacks = Utils::Callbacks::Chain.new
71
-
72
70
  class_attribute :after_authentication_failed_callbacks
71
+
72
+ self.after_session_expired_callbacks = Utils::Callbacks::Chain.new
73
73
  self.after_authentication_failed_callbacks = Utils::Callbacks::Chain.new
74
74
  end
75
75
  end
@@ -0,0 +1,64 @@
1
+ require 'hanami/authentication/version'
2
+ require 'bcrypt'
3
+ require 'securerandom'
4
+
5
+ module Hanami
6
+ module Authentication
7
+ module Token
8
+ private
9
+
10
+ def create_token
11
+ SecureRandom.uuid
12
+ end
13
+
14
+ def current_user
15
+ @current_user
16
+ end
17
+
18
+ def authenticate
19
+ bearer_token = token_from_header
20
+ halt 401 unless bearer_token
21
+ token = self.class.find_token_block.call(bearer_token)
22
+ halt 401 unless token
23
+ @current_user = self.class.find_user_block.call(token)
24
+ halt 401 unless @current_user
25
+ end
26
+
27
+ def authenticated?
28
+ !!@current_user
29
+ end
30
+
31
+ def token_from_header
32
+ header = request.get_header('Authorization')
33
+ return unless header
34
+ matched = header.match(/Bearer (.+)$/)
35
+ matched && matched[1]
36
+ end
37
+
38
+ def self.included(base)
39
+ base.class_eval do
40
+ _expose :current_user
41
+ extend ClassMethods
42
+ end
43
+ end
44
+
45
+ module ClassMethods
46
+ def self.extended(base)
47
+ base.class_eval do
48
+ include Utils::ClassAttribute
49
+ class_attribute :find_user_block
50
+ class_attribute :find_token_block
51
+ end
52
+ end
53
+
54
+ def user_for_authenticate(&blk)
55
+ self.find_user_block = blk
56
+ end
57
+
58
+ def token_for_authenticate(&blk)
59
+ self.find_token_block = blk
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
1
  module Hanami
2
2
  module Authentication
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LegalForce Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
@@ -97,6 +97,7 @@ files:
97
97
  - Rakefile
98
98
  - hanami-authentication.gemspec
99
99
  - lib/hanami/authentication.rb
100
+ - lib/hanami/authentication/token.rb
100
101
  - lib/hanami/authentication/version.rb
101
102
  homepage: https://github.com/legalforce/hanami-authentication
102
103
  licenses: