Skip to content

Commit

Permalink
Specify algorithm when decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
GabeIsman committed Jun 12, 2017
1 parent 6e392e1 commit 8084900
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/lib/login_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def self.decode(token: nil)
end

begin
payload, _config = JWT.decode(token, self.secret_key, 'HS256')
payload, _config = JWT.decode(token, self.secret_key, true, { algorithm: 'HS256' })
rescue JWT::ExpiredSignature
# If the token has expired, try again to decode it, but with expiration
# checking turned off, so we can tell who tried to log in.
begin
payload, _config = JWT.decode(token, self.secret_key, true, verify_expiration: false)
payload, _config = JWT.decode(token, self.secret_key, true, { algorithm: 'HS256', verify_expiration: false })

user_id = payload['data']['user_id']
user = User.find_by(id: user_id)

if user.blank?
return false
else
Expand Down

0 comments on commit 8084900

Please sign in to comment.