Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select jwk by kid #458

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.bulk_data_jwks
end

attr_reader :encryption_method, :scope, :iss, :sub, :aud, :content_type, :grant_type, :client_assertion_type, :exp,
:jti
:jti, :kid

def initialize(
encryption_method:,
Expand All @@ -24,7 +24,8 @@ def initialize(
grant_type: 'client_credentials',
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
exp: 5.minutes.from_now,
jti: SecureRandom.hex(32)
jti: SecureRandom.hex(32),
kid: nil
)
@encryption_method = encryption_method
@scope = scope
Expand All @@ -36,13 +37,15 @@ def initialize(
@client_assertion_type = client_assertion_type
@exp = exp
@jti = jti
@kid = kid
end

def bulk_private_key
@bulk_private_key ||=
self.class.bulk_data_jwks['keys']
.select { |key| key['key_ops']&.include?('sign') }
.find { |key| key['alg'] == encryption_method }
.select { |key| key['alg'] == encryption_method }
.find { |key| !kid || key['kid'] == kid }
end

def jwt_token
Expand Down
19 changes: 15 additions & 4 deletions lib/onc_certification_g10_test_kit/bulk_data_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class BulkDataAuthorization < Inferno::TestGroup
}
]
}
input :bulk_jwks_kid,
title: 'Bulk Data JWKS kid',
description: <<~DESCRIPTION,
The key ID of the JWKS private key to use for signing the client assertion when fetching an auth token.
Defaults to the first JWK in the list if no kid is supplied.
DESCRIPTION
optional: true
output :bearer_token

http_client :token_endpoint do
Expand Down Expand Up @@ -85,7 +92,8 @@ class BulkDataAuthorization < Inferno::TestGroup
iss: bulk_client_id,
sub: bulk_client_id,
aud: bulk_token_endpoint,
grant_type: 'not_a_grant_type')
grant_type: 'not_a_grant_type',
kid: bulk_jwks_kid)

post(**{ client: :token_endpoint }.merge(post_request_content))

Expand Down Expand Up @@ -116,7 +124,8 @@ class BulkDataAuthorization < Inferno::TestGroup
iss: bulk_client_id,
sub: bulk_client_id,
aud: bulk_token_endpoint,
client_assertion_type: 'not_an_assertion_type')
client_assertion_type: 'not_an_assertion_type',
kid: bulk_jwks_kid)

post(**{ client: :token_endpoint }.merge(post_request_content))

Expand Down Expand Up @@ -155,7 +164,8 @@ class BulkDataAuthorization < Inferno::TestGroup
scope: bulk_scope,
iss: 'not_a_valid_iss',
sub: bulk_client_id,
aud: bulk_token_endpoint)
aud: bulk_token_endpoint,
kid: bulk_jwks_kid)

post(**{ client: :token_endpoint }.merge(post_request_content))

Expand All @@ -177,7 +187,8 @@ class BulkDataAuthorization < Inferno::TestGroup
scope: bulk_scope,
iss: bulk_client_id,
sub: bulk_client_id,
aud: bulk_token_endpoint)
aud: bulk_token_endpoint,
kid: bulk_jwks_kid)

authentication_response = post(**{ client: :token_endpoint }.merge(post_request_content))

Expand Down
Loading