grape-knock 0.1.0 → 0.1.1

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: ab97d25b95a0a36b1648fadb345279f25475d52b
4
- data.tar.gz: 8053c81076cb1e41338fa83f49aaf0b799e37bef
3
+ metadata.gz: 4807209f1dd16ed6c0c7745e215459ce530937e1
4
+ data.tar.gz: cb81980c4e78683d4c08a1ec0a49a6b321d25197
5
5
  SHA512:
6
- metadata.gz: eb593d8ca042f942deecfa4922c7be79d9eb92c3f6bfd7329400d7febbd678af0268ffd2c61bd441a2e63d84ecd64f4a49a34c809ddbcda22b233b7c7823d437
7
- data.tar.gz: 457bd0bdcd0a88d430e1ce4610dbe70fb7edaf8895de5d1a2c05e34ebabd7d33d0d78540eff243368fef89d777976c03ae7b699f28d39d043855c69dcd68c70f
6
+ metadata.gz: fc945a605704f04fadca44f6ebe299a523baeb6c741d279c16cf6ceb730e80f5a4c10e88998294dba9c1a2e218301c303d8b1e1a85dfb4a213b0ac622fe1f77b
7
+ data.tar.gz: 97f6d59291a2033bb44addb752e53571485a6f5b3cfdc0802c2f1ee7584bac576c31f3a7204d1c373333bf6b360f81963aab312ab75200529b0c4e52ce80a049
@@ -1,25 +1,35 @@
1
1
  require 'knock'
2
2
  require 'knock/authenticable'
3
3
  require 'grape/knock/forbidden_error'
4
+ require 'grape/knock/methods'
4
5
 
5
6
  module Grape
6
7
  module Knock
7
8
  class Authenticable < Grape::Middleware::Base
8
9
  include ::Knock::Authenticable
9
10
 
10
- def token
11
- env['HTTP_AUTHORIZATION'].to_s.split(' ').last
11
+ def context
12
+ env['api.endpoint']
13
+ end
14
+
15
+ def before
16
+ authenticate
17
+ context.extend Grape::Knock::Methods
18
+ context.current_user = @current_user
12
19
  end
13
20
 
21
+ private
22
+
14
23
  def authenticate
15
24
  fail ::Grape::Knock::ForbiddenError unless token
16
- ::Knock::AuthToken.new(token: token).current_user
25
+ @current_user = ::Knock::AuthToken.new(token: token).current_user
26
+ fail ::Grape::Knock::ForbiddenError unless @current_user
17
27
  rescue ::JWT::DecodeError
18
28
  fail ::Grape::Knock::ForbiddenError
19
29
  end
20
30
 
21
- def before
22
- authenticate
31
+ def token
32
+ env['HTTP_AUTHORIZATION'].to_s.split(' ').last
23
33
  end
24
34
 
25
35
  end
@@ -0,0 +1,9 @@
1
+ module Grape
2
+ module Knock
3
+ module Methods
4
+
5
+ attr_accessor :current_user
6
+
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Knock
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-knock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
@@ -100,6 +100,7 @@ files:
100
100
  - lib/grape/knock.rb
101
101
  - lib/grape/knock/authenticable.rb
102
102
  - lib/grape/knock/forbidden_error.rb
103
+ - lib/grape/knock/methods.rb
103
104
  - lib/grape/knock/version.rb
104
105
  homepage: https://github.com/gottfrois/grape-knock
105
106
  licenses: