Class: JwtAuthorize::JwtDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt_authorize/jwt_decoder.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil, options = {}) ⇒ JwtDecoder

Returns a new instance of JwtDecoder.



16
17
18
19
# File 'lib/jwt_authorize/jwt_decoder.rb', line 16

def initialize(logger = nil, options = {})
  @logger = logger
  @options = options
end

Instance Method Details

#get_headers_from_jwt(token) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/jwt_authorize/jwt_decoder.rb', line 36

def get_headers_from_jwt(token)
  fail "token is nil" if token.nil?

  headers = token_from_header(token).split(".").first

  JSON.parse(Base64.decode64(headers))
end

#get_payload_from_jwt(header, certificate) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jwt_authorize/jwt_decoder.rb', line 21

def get_payload_from_jwt(header, certificate)
  fail "No certificate specified" unless certificate

  validate_header(header)

  token = token_from_header(header)

  decoded = decode_token(token, certificate)

  options = decoded.last
  validate_thumbprint(options[CERTIFICATE_THUMBPRINT], certificate)

  decoded
end