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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a943aa0b9dc65189852d3ab4584371c3254c2ee1
4
- data.tar.gz: 2a4f967cbef940a5d3fb5248b419d48adcdb324c
3
+ metadata.gz: 1ff009a39cd26ca42d11020a59e90af650018533
4
+ data.tar.gz: f0ee2214976c6101c39c8da3f14a50e2a5e3001c
5
5
  SHA512:
6
- metadata.gz: c15efeba186db245f32174ba86e8eec0e8939f7534d42e19cc05230a20ba9269994c17ecaab588d33cd32a6c77bab5386ec5146111d48430aa1443ce190403c8
7
- data.tar.gz: bb1c0da134318b6787b6571ec9c34b269095c0a9f5421d3186ed24ce3ba6c27e6f6494be83dbcca8d90632bcafea06db852ae80311c863e252aa8141bbb6c5d9
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"
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Doorkeeper
2
2
  module JWT
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper-jwt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Warren