Module: DecodeThis

Defined in:
lib/decode_this.rb,
lib/decode_this/version.rb,
lib/decode_this/safe_decoding.rb

Defined Under Namespace

Classes: SafeDecoding

Constant Summary collapse

VERSION =
'0.1.7'
BaseError =
Class.new(RuntimeError)
ConfigFileNotFoundError =
Class.new(BaseError)
KeyFileNotFoundError =
Class.new(BaseError)
DecodeError =
Class.new(BaseError)

Class Method Summary collapse

Class Method Details

.configObject



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

def self.config
  raise ConfigFileNotFoundError.new("Cannot found configuration file in #{@config_path}") unless @config_path

  @config ||= YAML.load(File.open(@config_path))[@env]
end

.config_pathObject



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

def self.config_path
  @config_path
end

.config_path=(config_path) ⇒ Object



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

def self.config_path=(config_path)
  @config_path = File.expand_path(config_path)
end

.decode(header_value) ⇒ Object



8
9
10
11
12
# File 'lib/decode_this.rb', line 8

def self.decode(header_value)
  token = token_from_header(header_value)

  safe_decode { JWT.decode(token, public_key, true, algorithm: config['algorithm']).first }
end

.envObject



40
41
42
# File 'lib/decode_this.rb', line 40

def self.env
  @env
end

.env=(env) ⇒ Object



36
37
38
# File 'lib/decode_this.rb', line 36

def self.env=(env)
  @env = env.to_s
end

.loggerObject



28
29
30
# File 'lib/decode_this.rb', line 28

def self.logger
  @logger
end

.logger=(logger) ⇒ Object



32
33
34
# File 'lib/decode_this.rb', line 32

def self.logger=(logger)
  @logger = logger
end