Module: JwtAuthToken
- Defined in:
- lib/jwt_auth_token.rb
Instance Method Summary collapse
- #is_jwt_valid_token? ⇒ Boolean
- #jwt_algorithm ⇒ Object
- #jwt_header_name ⇒ Object
- #jwt_header_token ⇒ Object
- #jwt_hmac_secret ⇒ Object
- #jwt_set_header(data) ⇒ Object
- #validate_keys ⇒ Object
Instance Method Details
#is_jwt_valid_token? ⇒ Boolean
26 27 28 29 30 31 32 33 |
# File 'lib/jwt_auth_token.rb', line 26 def is_jwt_valid_token? begin @decoded_token = JSON.parse(JWT.decode(jwt_header_token, jwt_hmac_secret, true, { :algorithm => jwt_algorithm })[0]) return validate_keys rescue Exception => e return false end end |
#jwt_algorithm ⇒ Object
9 10 11 |
# File 'lib/jwt_auth_token.rb', line 9 def jwt_algorithm @_jwt_algorithm ||= 'HS512' end |
#jwt_header_name ⇒ Object
18 19 20 |
# File 'lib/jwt_auth_token.rb', line 18 def jwt_header_name @_jwt_header_name ||= "embibe-token" end |
#jwt_header_token ⇒ Object
22 23 24 |
# File 'lib/jwt_auth_token.rb', line 22 def jwt_header_token @_jwt_header_token ||= request.headers[jwt_header_name] rescue nil end |
#jwt_hmac_secret ⇒ Object
5 6 7 |
# File 'lib/jwt_auth_token.rb', line 5 def jwt_hmac_secret @_jwt_hmac_secret ||= Rails.application.secrets[:secret_key_base] end |
#jwt_set_header(data) ⇒ Object
13 14 15 16 |
# File 'lib/jwt_auth_token.rb', line 13 def jwt_set_header(data) encoded_token = JWT.encode(data,jwt_hmac_secret,jwt_algorithm) response.set_header(jwt_header_name, encoded_token) end |
#validate_keys ⇒ Object
35 36 37 |
# File 'lib/jwt_auth_token.rb', line 35 def validate_keys !!@_validate_keys ||= (@decoded_token.keys && ["id", "email"]).any? end |