lib/doorkeeper-jwt.rb in doorkeeper-jwt-0.1.7 vs lib/doorkeeper-jwt.rb in doorkeeper-jwt-0.1.8
- old
+ new
@@ -43,13 +43,22 @@
def use_application_secret?
Doorkeeper::JWT.configuration.use_application_secret
end
def application_secret(opts)
- opts = { application: {} }.merge(opts)
- return opts[:application][:secret] if opts[:application][:secret]
- fail "JWT `use_application_secret` config set, but no app secret set."
+ if opts[:application].nil?
+ fail "JWT `use_application_secret` is enabled but application is " \
+ "nil. This can happen if `client_id` was absent in the request " \
+ "params."
+ end
+
+ if opts[:application][:secret].nil?
+ fail "JWT `use_application_secret` is enabled but the application " \
+ "secret is nil."
+ end
+
+ opts[:application][:secret]
end
def rsa_encryption?
/RS\d{3}/ =~ encryption_method
end
@@ -65,18 +74,18 @@
def ecdsa_key
OpenSSL::PKey::EC.new(Doorkeeper::JWT.configuration.secret_key)
end
def rsa_key_file
- OpenSSL::PKey::RSA.new(secret_key_file_open)
+ secret_key_file_open { |f| OpenSSL::PKey::RSA.new(f) }
end
def ecdsa_key_file
- OpenSSL::PKey::EC.new(secret_key_file_open)
+ secret_key_file_open { |f| OpenSSL::PKey::EC.new(f) }
end
- def secret_key_file_open
- File.open(Doorkeeper::JWT.configuration.secret_key_path)
+ def secret_key_file_open(&block)
+ File.open(Doorkeeper::JWT.configuration.secret_key_path, &block)
end
end
end
end