Class: JSON::JWT
- Inherits:
-
Hash
- Object
- Hash
- JSON::JWT
- Defined in:
- lib/json/jwt.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#signature ⇒ Object
Returns the value of attribute signature.
Instance Method Summary collapse
-
#initialize(claim) ⇒ JWT
constructor
A new instance of JWT.
- #sign(private_key_or_secret, algorithm = :RS256) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(claim) ⇒ JWT
Returns a new instance of JWT.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/json/jwt.rb', line 9 def initialize(claim) @header = { :typ => :JWT, :alg => :none } [:exp, :nbf, :iat].each do |key| if claim[key] claim[key] = claim[key].to_i end end replace claim end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
7 8 9 |
# File 'lib/json/jwt.rb', line 7 def header @header end |
#signature ⇒ Object
Returns the value of attribute signature.
7 8 9 |
# File 'lib/json/jwt.rb', line 7 def signature @signature end |
Instance Method Details
#sign(private_key_or_secret, algorithm = :RS256) ⇒ Object
22 23 24 |
# File 'lib/json/jwt.rb', line 22 def sign(private_key_or_secret, algorithm = :RS256) JWS.new(self).sign(private_key_or_secret, algorithm) end |
#to_s ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/json/jwt.rb', line 26 def to_s [ header.to_json, self.to_json, signature ].collect do |segment| UrlSafeBase64.encode64 segment.to_s end.join('.') end |