Module: JwtAuthToken

Defined in:
lib/jwt_auth_token.rb

Instance Method Summary collapse

Instance Method Details

#is_jwt_valid_token?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
# File 'lib/jwt_auth_token.rb', line 28

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_algorithmObject



11
12
13
# File 'lib/jwt_auth_token.rb', line 11

def jwt_algorithm
  @_jwt_algorithm ||= 'HS512'
end

#jwt_header_nameObject



20
21
22
# File 'lib/jwt_auth_token.rb', line 20

def jwt_header_name
  @_jwt_header_name ||= "embibe-token"
end

#jwt_header_tokenObject



24
25
26
# File 'lib/jwt_auth_token.rb', line 24

def jwt_header_token
  @_jwt_header_token ||= request.headers[jwt_header_name] rescue nil
end

#jwt_hmac_secretObject



7
8
9
# File 'lib/jwt_auth_token.rb', line 7

def jwt_hmac_secret
  @_jwt_hmac_secret ||= Rails.application.secrets[:secret_key_base]
end

#jwt_set_header(data) ⇒ Object



15
16
17
18
# File 'lib/jwt_auth_token.rb', line 15

def jwt_set_header(data)
  encoded_token = JWT.encode(data,jwt_hmac_secret,jwt_algorithm)
  response.set_header(jwt_header_name, encoded_token)
end