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.
-
#custom_jwks ⇒ Object
readonly
Returns the value of attribute custom_jwks.
-
#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, custom_jwks: nil) ⇒ ClientAssertionBuilder
constructor
A new instance of ClientAssertionBuilder.
- #jwks ⇒ Object
- #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, custom_jwks: nil) ⇒ ClientAssertionBuilder
Returns a new instance of ClientAssertionBuilder.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 23 def initialize( client_auth_encryption_method:, iss:, sub:, aud:, exp: 5.minutes.from_now.to_i, jti: SecureRandom.hex(32), kid: nil, custom_jwks: 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.presence @custom_jwks = custom_jwks 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 |
#custom_jwks ⇒ Object (readonly)
Returns the value of attribute custom_jwks.
11 12 13 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 11 def custom_jwks @custom_jwks 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
80 81 82 83 84 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 80 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 |
#jwks ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 46 def jwks @jwks ||= if custom_jwks.present? JWT::JWK::Set.new(JSON.parse(custom_jwks)) else JWKS.jwks end end |
#jwt_payload ⇒ Object
63 64 65 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 63 def jwt_payload { iss:, sub:, aud:, exp:, jti: }.compact end |
#key_id ⇒ Object
76 77 78 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 76 def key_id @private_key['kid'] end |
#private_key ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 55 def private_key @private_key ||= 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
67 68 69 70 71 72 73 74 |
# File 'lib/smart_app_launch/client_assertion_builder.rb', line 67 def signing_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 @private_key.signing_key end |