Module: JwtHandlerRuby

Defined in:
lib/jwt_handler_ruby.rb,
lib/jwt_handler_ruby/engine.rb,
lib/jwt_handler_ruby/version.rb,
app/jobs/jwt_handler_ruby/application_job.rb,
app/helpers/jwt_handler_ruby/logins_helper.rb,
app/models/jwt_handler_ruby/application_record.rb,
app/helpers/jwt_handler_ruby/application_helper.rb,
app/mailers/jwt_handler_ruby/application_mailer.rb,
app/controllers/jwt_handler_ruby/logins_controller.rb,
app/controllers/jwt_handler_ruby/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, LoginsHelper Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Engine, LoginsController

Constant Summary collapse

VERSION =
'0.0.3'

Class Method Summary collapse

Class Method Details

.decode_user(jwt) ⇒ Object



4
5
6
7
# File 'lib/jwt_handler_ruby.rb', line 4

def self.decode_user(jwt)
  pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
  JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
end

.valid_jwt?(jwt) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/jwt_handler_ruby.rb', line 9

def self.valid_jwt?(jwt)
  pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
  begin
    JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
  rescue JWT::DecodeError
    return false
  end
  true
end