Class: JSONWebToken::RSAToken

Inherits:
Token
  • Object
show all
Defined in:
lib/json_web_token/rsa_token.rb

Constant Summary collapse

ALGORITHM =
'RS256'

Constants inherited from Token

Token::DEFAULT_EXPIRE_TIME, Token::DEFAULT_NOT_BEFORE_TIME

Instance Attribute Summary collapse

Attributes inherited from Token

#audience, #expire_time, #id, #issued_at, #issuer, #not_before, #subject

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Token

#[], #[]=, #payload

Constructor Details

#initialize(key_file) ⇒ RSAToken

Returns a new instance of RSAToken.



9
10
11
12
# File 'lib/json_web_token/rsa_token.rb', line 9

def initialize(key_file)
  super()
  @key_file = key_file
end

Instance Attribute Details

#key_fileObject (readonly)

Returns the value of attribute key_file.



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

def key_file
  @key_file
end

Class Method Details

.decode(token, key) ⇒ Object



23
24
25
# File 'lib/json_web_token/rsa_token.rb', line 23

def self.decode(token, key)
  JWT.decode(token, key, true, { algorithm: ALGORITHM })
end

.encode(payload, key, kid) ⇒ Object



18
19
20
21
# File 'lib/json_web_token/rsa_token.rb', line 18

def self.encode(payload, key, kid)
  headers = { kid: kid, typ: 'JWT' }
  JWT.encode(payload, key, ALGORITHM, headers)
end

Instance Method Details

#encodedObject



14
15
16
# File 'lib/json_web_token/rsa_token.rb', line 14

def encoded
  self.class.encode(payload, key, kid)
end