Class: JWTear::JWS
- Inherits:
-
Object
- Object
- JWTear::JWS
- Includes:
- Helpers::Extensions::Print
- Defined in:
- lib/jwtear/jws.rb
Overview
JWS
Takes a parsed token from JSON::JWT#decode
Instance Attribute Summary collapse
-
#alg ⇒ Object
Returns the value of attribute alg.
-
#at_hash ⇒ Object
Returns the value of attribute at_hash.
-
#aud ⇒ Object
Returns the value of attribute aud.
-
#azp ⇒ Object
Returns the value of attribute azp.
-
#cty ⇒ Object
Returns the value of attribute cty.
-
#email ⇒ Object
Returns the value of attribute email.
-
#email_verified ⇒ Object
Returns the value of attribute email_verified.
-
#exp ⇒ Object
Returns the value of attribute exp.
-
#hd ⇒ Object
Returns the value of attribute hd.
-
#header ⇒ Object
Returns the value of attribute header.
-
#iat ⇒ Object
Returns the value of attribute iat.
-
#iss ⇒ Object
Returns the value of attribute iss.
-
#jku ⇒ Object
Returns the value of attribute jku.
-
#kid ⇒ Object
Returns the value of attribute kid.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#signature ⇒ Object
Returns the value of attribute signature.
-
#sub ⇒ Object
Returns the value of attribute sub.
-
#typ ⇒ Object
Returns the value of attribute typ.
Instance Method Summary collapse
-
#generate_jws(header:, payload:, key:) ⇒ String
generate_jws generate JWS token.
-
#parse(token) ⇒ Self
parse is a basic parser for JWS token.
- #to_json_presentation ⇒ Object
Methods included from Helpers::Extensions::Print
#print_bad, #print_error, #print_good, #print_h1, #print_h2, #print_h3, #print_status, #print_warning
Instance Attribute Details
#alg ⇒ Object
Returns the value of attribute alg.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def alg @alg end |
#at_hash ⇒ Object
Returns the value of attribute at_hash.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def at_hash @at_hash end |
#aud ⇒ Object
Returns the value of attribute aud.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def aud @aud end |
#azp ⇒ Object
Returns the value of attribute azp.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def azp @azp end |
#cty ⇒ Object
Returns the value of attribute cty.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def cty @cty end |
#email ⇒ Object
Returns the value of attribute email.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def email @email end |
#email_verified ⇒ Object
Returns the value of attribute email_verified.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def email_verified @email_verified end |
#exp ⇒ Object
Returns the value of attribute exp.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def exp @exp end |
#hd ⇒ Object
Returns the value of attribute hd.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def hd @hd end |
#header ⇒ Object
Returns the value of attribute header.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def header @header end |
#iat ⇒ Object
Returns the value of attribute iat.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def iat @iat end |
#iss ⇒ Object
Returns the value of attribute iss.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def iss @iss end |
#jku ⇒ Object
Returns the value of attribute jku.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def jku @jku end |
#kid ⇒ Object
Returns the value of attribute kid.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def kid @kid end |
#payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def payload @payload end |
#signature ⇒ Object
Returns the value of attribute signature.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def signature @signature end |
#sub ⇒ Object
Returns the value of attribute sub.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def sub @sub end |
#typ ⇒ Object
Returns the value of attribute typ.
8 9 10 |
# File 'lib/jwtear/jws.rb', line 8 def typ @typ end |
Instance Method Details
#generate_jws(header:, payload:, key:) ⇒ String
generate_jws
generate JWS token
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jwtear/jws.rb', line 54 def generate_jws(header:, payload:, key:) jwt = JSON::JWT.new(JSON.parse(payload, symbolize_names: true)) jwt.header = JSON.parse(header, symbolize_names: true) handle_signing(jwt, key) rescue JSON::JWS::UnexpectedAlgorithm => e puts "Unexpected algorithm '#{jwt.header[:alg]}'." puts e. exit! rescue Exception => e print_error e. end |
#parse(token) ⇒ Self
parse
is a basic parser for JWS token
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jwtear/jws.rb', line 21 def parse(token) jwt = JSON::JWT.decode(token, :skip_verification) @header = jwt.header @payload = jwt.to_h @signature = jwt.signature @alg = @header["alg"] @typ = @header["typ"] @cty = @header["cty"] @kid = @header["kid"] @jku = @header["jku"] @iat = @payload["iat"] self rescue JSON::JWT::InvalidFormat => e print_error e. puts token exit! rescue Exception => e puts e. end |
#to_json_presentation ⇒ Object
41 42 43 |
# File 'lib/jwtear/jws.rb', line 41 def to_json_presentation "#{@header.to_json}" + ".".bold + "#{@payload.to_json}" + ".".bold + "#{Base64.urlsafe_encode64(@signature, padding: false)}" end |