Skip to content

Commit 8f06a97

Browse files
authored
Merge pull request #652 from mridang/feat/jwt-kid-support
2 parents a5de787 + 5f4251e commit 8f06a97

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

.rubocop_gradual.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"spec/oauth2/response_spec.rb:2248532534": [
6969
[3, 1, 31, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/response*_spec.rb`.", 3190869319]
7070
],
71-
"spec/oauth2/strategy/assertion_spec.rb:793170256": [
71+
"spec/oauth2/strategy/assertion_spec.rb:3524328522": [
7272
[6, 1, 42, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/strategy/assertion*_spec.rb`.", 3665690869]
7373
],
7474
"spec/oauth2/strategy/auth_code_spec.rb:142083698": [

lib/oauth2/strategy/assertion.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def build_request(assertion, request_opts = {})
9595
def build_assertion(claims, encoding_opts)
9696
raise ArgumentError.new(message: "Please provide an encoding_opts hash with :algorithm and :key") if !encoding_opts.is_a?(Hash) || (%i[algorithm key] - encoding_opts.keys).any?
9797

98-
JWT.encode(claims, encoding_opts[:key], encoding_opts[:algorithm])
98+
headers = {}
99+
headers[:kid] = encoding_opts[:kid] if encoding_opts.key?(:kid)
100+
101+
JWT.encode(claims, encoding_opts[:key], encoding_opts[:algorithm], headers)
99102
end
100103
end
101104
end

spec/oauth2/strategy/assertion_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@
164164
expect { client_assertion.get_token(claims, encoding_opts) }.to raise_error(ArgumentError, /encoding_opts/)
165165
end
166166
end
167+
168+
context "when including a Key ID (kid)" do
169+
let(:algorithm) { "HS256" }
170+
let(:key) { "new_secret_key" }
171+
let(:kid) { "my_super_secure_key_id_123" }
172+
173+
before do
174+
client_assertion.get_token(claims, algorithm: algorithm, key: key, kid: kid)
175+
raise "No request made!" if @request_body.nil?
176+
end
177+
178+
it_behaves_like "encodes the JWT"
179+
180+
it "includes the kid in the JWT header" do
181+
expect(header).not_to be_nil
182+
expect(header["kid"]).to eq(kid)
183+
end
184+
end
167185
end
168186
end
169187

0 commit comments

Comments
 (0)