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 +4 -4
- data/lib/grape/knock/authenticable.rb +15 -5
- data/lib/grape/knock/methods.rb +9 -0
- data/lib/grape/knock/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4807209f1dd16ed6c0c7745e215459ce530937e1
|
4
|
+
data.tar.gz: cb81980c4e78683d4c08a1ec0a49a6b321d25197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
11
|
-
env['
|
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
|
22
|
-
|
31
|
+
def token
|
32
|
+
env['HTTP_AUTHORIZATION'].to_s.split(' ').last
|
23
33
|
end
|
24
34
|
|
25
35
|
end
|
data/lib/grape/knock/version.rb
CHANGED
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.
|
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:
|