Class: SMARTAppLaunch::ClientAssertionBuilder
- Inherits:
-
Object
- Object
- SMARTAppLaunch::ClientAssertionBuilder
- Defined in:
- lib/smart_app_launch/client_assertion_builder.rb
Instance Attribute Summary collapse
-
#aud ⇒ Object
readonly
Returns the value of attribute aud.
-
#client_assertion_type ⇒ Object
readonly
Returns the value of attribute client_assertion_type.
-
#client_auth_encryption_method ⇒ Object
readonly
Returns the value of attribute client_auth_encryption_method.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#exp ⇒ Object
readonly
Returns the value of attribute exp.
-
#grant_type ⇒ Object
readonly
Returns the value of attribute grant_type.
-
#iss ⇒ Object
readonly
Returns the value of attribute iss.
-
#jti ⇒ Object
readonly
Returns the value of attribute jti.
-
#kid ⇒ Object
readonly
Returns the value of attribute kid.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
Class Method Summary collapse
Instance Method Summary collapse
- #client_assertion ⇒ Object
-
#initialize(client_auth_encryption_method:, iss:, sub:, aud:, exp: 5.minutes.from_now.to_i, jti: SecureRandom.hex(32), kid: nil) ⇒ ClientAssertionBuilder
constructor
A new instance of ClientAssertionBuilder.
- #jwt_payload ⇒ Object
- #key_id ⇒ Object
- #private_key ⇒ Object
- #signing_key ⇒ Object
Constructor Details
#initialize(client_auth_encryption_method:, iss:, sub:, aud:, exp: 5.minutes.from_now.to_i, jti: SecureRandom.hex(32), kid: nil) ⇒ ClientAssertionBuilder
Returns a new instance of ClientAssertionBuilder.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 22 def initialize( client_auth_encryption_method:, iss:, sub:, aud:, exp: 5.minutes.from_now.to_i, jti: SecureRandom.hex(32), kid: nil ) @client_auth_encryption_method = client_auth_encryption_method @iss = iss @sub = sub @aud = aud @content_type = content_type @grant_type = grant_type @client_assertion_type = client_assertion_type @exp = exp @jti = jti @kid = kid end |
Instance Attribute Details
#aud ⇒ Object (readonly)
Returns the value of attribute aud.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def aud @aud end |
#client_assertion_type ⇒ Object (readonly)
Returns the value of attribute client_assertion_type.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def client_assertion_type @client_assertion_type end |
#client_auth_encryption_method ⇒ Object (readonly)
Returns the value of attribute client_auth_encryption_method.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def client_auth_encryption_method @client_auth_encryption_method end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def content_type @content_type end |
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def exp @exp end |
#grant_type ⇒ Object (readonly)
Returns the value of attribute grant_type.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def grant_type @grant_type end |
#iss ⇒ Object (readonly)
Returns the value of attribute iss.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def iss @iss end |
#jti ⇒ Object (readonly)
Returns the value of attribute jti.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def jti @jti end |
#kid ⇒ Object (readonly)
Returns the value of attribute kid.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def kid @kid end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def sub @sub end |
Class Method Details
.build ⇒ Object
7 8 9 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 7 def self.build(...) new(...).client_assertion end |
Instance Method Details
#client_assertion ⇒ Object
66 67 68 69 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 66 def client_assertion @client_assertion ||= JWT.encode jwt_payload, signing_key, client_auth_encryption_method, { alg: client_auth_encryption_method, kid: key_id, typ: 'JWT' } end |
#jwt_payload ⇒ Object
50 51 52 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 50 def jwt_payload { iss:, sub:, aud:, exp:, jti: }.compact end |
#key_id ⇒ Object
62 63 64 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 62 def key_id @private_key['kid'] end |
#private_key ⇒ Object
43 44 45 46 47 48 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 43 def private_key @private_key ||= JWKS.jwks .select { |key| key[:key_ops]&.include?('sign') } .select { |key| key[:alg] == client_auth_encryption_method } .find { |key| !kid || key[:kid] == kid } end |
#signing_key ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 54 def signing_key private_key() if @private_key.nil? raise Inferno::Exceptions::AssertionException, "No signing key found for inputs: encryption method = '#{client_auth_encryption_method}' and kid = '#{kid}'" end return @private_key.signing_key end |