Skip to content

Commit

Permalink
clean up jwt key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Sep 17, 2018
1 parent d9c9fdd commit 685692b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions app/models/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,14 @@ def generate_pkcs1_pss_signed_key!

def generate_jwt_rs256_key!
priv = OpenSSL::PKey::RSA.new account.private_key
begin
payload = JSON.parse key
jwt = JWT.encode payload, priv, "RS256"

self.key = jwt
rescue JSON::GeneratorError,
JSON::ParserError
errors.add :key, :jwt_payload_invalid, message: "key is not a valid JWT payload (must be a valid JSON encoded string)"
rescue JWT::InvalidPayload => e
errors.add :key, :jwt_payload_invalid, message: "key is not a valid JWT payload (#{e.message})"
end
payload = JSON.parse key
jwt = JWT.encode payload, priv, "RS256"

self.key = jwt
rescue JSON::GeneratorError,
JSON::ParserError
errors.add :key, :jwt_payload_invalid, message: "key is not a valid JWT payload (must be a valid JSON encoded string)"
rescue JWT::InvalidPayload => e
errors.add :key, :jwt_payload_invalid, message: "key is not a valid JWT payload (#{e.message})"
end
end
2 changes: 1 addition & 1 deletion features/step_definitions/request_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
end
end

Then /^the JSON response should (?:contain|be) an? "([^\"]*)" with the following "([^\"]*)":$/ do |name, attribute, body|
Then /^the JSON response should (?:contain|be) an? "([^\"]*)" with the following "([^\"]*)":$/ do |resource, attribute, body|
json = JSON.parse last_response.body

expect(json["data"]["type"]).to eq resource.pluralize
Expand Down

0 comments on commit 685692b

Please sign in to comment.