doorkeeper-jwt 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/doorkeeper-jwt.rb +15 -2
- data/lib/doorkeeper-jwt/config.rb +12 -0
- data/lib/doorkeeper-jwt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ff009a39cd26ca42d11020a59e90af650018533
|
4
|
+
data.tar.gz: f0ee2214976c6101c39c8da3f14a50e2a5e3001c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39a38a9e249066e0aad3ce653c94051b3ef9febb47207b9f5dd2bd2e1f090165c3b04ed5372f55fd9a357290e3c61f92d6c5f45aba460e1476859186ba1bf370
|
7
|
+
data.tar.gz: e12b95128803fe60e577537ba93e3fc810003491c34e2f84a8ed7ccc59aa360e8168592f9f2228560305f809e2a322e33b535708c6396d6d4065ce6f9e351634
|
data/README.md
CHANGED
@@ -53,6 +53,11 @@ Doorkeeper::JWT.configure do
|
|
53
53
|
}
|
54
54
|
end
|
55
55
|
|
56
|
+
# Use the application secret specified in the Access Grant token
|
57
|
+
# Defaults to false
|
58
|
+
# If you specify `use_application_secret true`, both secret_key and secret_key_path will be ignored
|
59
|
+
use_application_secret false
|
60
|
+
|
56
61
|
# Set the encryption secret. This would be shared with any other applications
|
57
62
|
# that should be able to read the payload of the token.
|
58
63
|
# Defaults to "secret"
|
data/lib/doorkeeper-jwt.rb
CHANGED
@@ -8,7 +8,7 @@ module Doorkeeper
|
|
8
8
|
def generate(opts = {})
|
9
9
|
::JWT.encode(
|
10
10
|
token_payload(opts),
|
11
|
-
secret_key,
|
11
|
+
secret_key(opts),
|
12
12
|
encryption_method
|
13
13
|
)
|
14
14
|
end
|
@@ -19,7 +19,10 @@ module Doorkeeper
|
|
19
19
|
Doorkeeper::JWT.configuration.token_payload.call opts
|
20
20
|
end
|
21
21
|
|
22
|
-
def secret_key
|
22
|
+
def secret_key(opts)
|
23
|
+
opts = { application: {} }.merge(opts)
|
24
|
+
|
25
|
+
return application_secret(opts) if use_application_secret?
|
23
26
|
return secret_key_file unless secret_key_file.nil?
|
24
27
|
return rsa_key if rsa_encryption?
|
25
28
|
return ecdsa_key if ecdsa_encryption?
|
@@ -37,6 +40,16 @@ module Doorkeeper
|
|
37
40
|
Doorkeeper::JWT.configuration.encryption_method.to_s.upcase
|
38
41
|
end
|
39
42
|
|
43
|
+
def use_application_secret?
|
44
|
+
return false unless Doorkeeper::JWT.configuration.use_application_secret
|
45
|
+
end
|
46
|
+
|
47
|
+
def application_secret(opts)
|
48
|
+
opts = { application: {} }.merge(opts)
|
49
|
+
return opts[:application][:secret] if opts[:application][:secret]
|
50
|
+
fail "JWT `use_application_secret` config set, but no app secret set."
|
51
|
+
end
|
52
|
+
|
40
53
|
def rsa_encryption?
|
41
54
|
/RS\d{3}/ =~ encryption_method
|
42
55
|
end
|
@@ -25,6 +25,13 @@ module Doorkeeper
|
|
25
25
|
@config
|
26
26
|
end
|
27
27
|
|
28
|
+
def use_application_secret(use_application_secret)
|
29
|
+
@config.instance_variable_set(
|
30
|
+
"@use_application_secret",
|
31
|
+
use_application_secret
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
28
35
|
def secret_key(secret_key)
|
29
36
|
@config.instance_variable_set('@secret_key', secret_key)
|
30
37
|
end
|
@@ -104,10 +111,15 @@ module Doorkeeper
|
|
104
111
|
|
105
112
|
option :token_payload,
|
106
113
|
default: proc{ { token: SecureRandom.method(:hex) } }
|
114
|
+
option :use_application_secret, default: false
|
107
115
|
option :secret_key, default: nil
|
108
116
|
option :secret_key_path, default: nil
|
109
117
|
option :encryption_method, default: nil
|
110
118
|
|
119
|
+
def use_application_secret
|
120
|
+
@use_application_secret ||= false
|
121
|
+
end
|
122
|
+
|
111
123
|
def secret_key
|
112
124
|
@secret_key ||= nil
|
113
125
|
end
|