Class: DaVinciCRDTestKit::JwtHelper
- Inherits:
-
Object
- Object
- DaVinciCRDTestKit::JwtHelper
- Defined in:
- lib/davinci_crd_test_kit/server/jwt_helper.rb
Instance Attribute Summary collapse
-
#aud ⇒ Object
readonly
Returns the value of attribute aud.
-
#encryption_method ⇒ Object
readonly
Returns the value of attribute encryption_method.
-
#exp ⇒ Object
readonly
Returns the value of attribute exp.
-
#iat ⇒ Object
readonly
Returns the value of attribute iat.
-
#iss ⇒ Object
readonly
Returns the value of attribute iss.
-
#jku ⇒ Object
readonly
Returns the value of attribute jku.
-
#jti ⇒ Object
readonly
Returns the value of attribute jti.
-
#kid ⇒ Object
readonly
Returns the value of attribute kid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(aud:, encryption_method:, iss:, jku:, iat: Time.now.to_i, exp: 5.minutes.from_now.to_i, jti: SecureRandom.hex(32), kid: nil) ⇒ JwtHelper
constructor
A new instance of JwtHelper.
- #jwt_header ⇒ Object
- #jwt_payload ⇒ Object
- #key_id ⇒ Object
- #private_key ⇒ Object
- #signed_jwt ⇒ Object
- #signing_key ⇒ Object
Constructor Details
#initialize(aud:, encryption_method:, iss:, jku:, iat: Time.now.to_i, exp: 5.minutes.from_now.to_i, jti: SecureRandom.hex(32), kid: nil) ⇒ JwtHelper
Returns a new instance of JwtHelper.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 11 def initialize( aud:, encryption_method:, iss:, jku:, iat: Time.now.to_i, exp: 5.minutes.from_now.to_i, jti: SecureRandom.hex(32), kid: nil ) @aud = aud @encryption_method = encryption_method @iss = iss @jku = jku @iat = iat @exp = exp @jti = jti @kid = kid end |
Instance Attribute Details
#aud ⇒ Object (readonly)
Returns the value of attribute aud.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def aud @aud end |
#encryption_method ⇒ Object (readonly)
Returns the value of attribute encryption_method.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def encryption_method @encryption_method end |
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def exp @exp end |
#iat ⇒ Object (readonly)
Returns the value of attribute iat.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def iat @iat end |
#iss ⇒ Object (readonly)
Returns the value of attribute iss.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def iss @iss end |
#jku ⇒ Object (readonly)
Returns the value of attribute jku.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def jku @jku end |
#jti ⇒ Object (readonly)
Returns the value of attribute jti.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def jti @jti end |
#kid ⇒ Object (readonly)
Returns the value of attribute kid.
9 10 11 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 9 def kid @kid end |
Class Method Details
.build ⇒ Object
5 6 7 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 5 def self.build(...) new(...).signed_jwt end |
Instance Method Details
#jwt_header ⇒ Object
47 48 49 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 47 def jwt_header { alg: encryption_method, typ: 'JWT', kid: key_id, jku: } end |
#jwt_payload ⇒ Object
51 52 53 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 51 def jwt_payload { iss:, aud:, exp:, iat:, jti: } end |
#key_id ⇒ Object
55 56 57 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 55 def key_id @private_key['kid'] end |
#private_key ⇒ Object
31 32 33 34 35 36 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 31 def private_key @private_key ||= JWKS.jwks .select { |key| key[:key_ops]&.include?('sign') } .select { |key| key[:alg] == encryption_method } .find { |key| !kid || key[:kid] == kid } end |
#signed_jwt ⇒ Object
59 60 61 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 59 def signed_jwt @signed_jwt ||= JWT.encode jwt_payload, signing_key, encryption_method, jwt_header end |
#signing_key ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/davinci_crd_test_kit/server/jwt_helper.rb', line 38 def signing_key if private_key.nil? raise Inferno::Exceptions::AssertionException, "No signing key found for inputs: encryption method = '#{encryption_method}' and kid = '#{kid}'" end @private_key.signing_key end |