Skip to content

Commit d2945da

Browse files
committed
bug: Don't require nonce
1 parent fb32621 commit d2945da

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

lib/doorkeeper/openid_connect/oauth/authorization/code.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ module Authorization
55
module Code
66
def issue_token
77
super.tap do |access_grant|
8-
::Doorkeeper::OpenidConnect::Nonce.create!(
9-
access_grant: access_grant,
10-
nonce: pre_auth.nonce
11-
)
8+
if pre_auth.nonce
9+
::Doorkeeper::OpenidConnect::Nonce.create!(
10+
access_grant: access_grant,
11+
nonce: pre_auth.nonce
12+
)
13+
end
1214
end
1315
end
1416
end

lib/doorkeeper/openid_connect/oauth/authorization_code_request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module AuthorizationCodeRequest
66

77
def after_successful_response
88
super
9-
id_token = Doorkeeper::OpenidConnect::Models::IdToken.new(access_token, grant.openid_connect_nonce.use!)
9+
id_token = Doorkeeper::OpenidConnect::Models::IdToken.new(access_token, grant.openid_connect_nonce.try(:use!))
1010
@response.id_token = id_token
1111
end
1212
end

spec/lib/oauth/authorization/code_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
})
2929
end
3030

31+
it 'does not store the nonce if not present' do
32+
allow(pre_auth).to receive(:nonce) { nil }
33+
subject.issue_token
34+
35+
expect(Doorkeeper::OpenidConnect::Nonce).to_not have_received(:create!)
36+
end
37+
3138
it 'returns the created grant' do
3239
expect(subject.issue_token).to be_a Doorkeeper::AccessGrant
3340
end
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
require 'rails_helper'
22

33
describe Doorkeeper::OpenidConnect::OAuth::AuthorizationCodeRequest do
4-
subject { Doorkeeper::OAuth::AuthorizationCodeRequest.new server, grant, client }
4+
subject {
5+
Doorkeeper::OAuth::AuthorizationCodeRequest.new(server, grant, client).tap do |request|
6+
request.instance_variable_set '@response', response
7+
request.access_token = token
8+
end
9+
}
10+
511
let(:server) { double }
612
let(:client) { double }
713
let(:grant) { create :access_grant, openid_connect_nonce: nonce }
@@ -11,12 +17,17 @@
1117

1218
describe '#after_successful_response' do
1319
it 'adds the ID token to the response' do
14-
subject.instance_variable_set '@response', response
15-
subject.access_token = token
1620
subject.send :after_successful_response
1721

1822
expect(response.id_token).to be_a Doorkeeper::OpenidConnect::Models::IdToken
1923
expect(response.id_token.nonce).to eq '123456'
2024
end
25+
26+
it 'skips the nonce if not present' do
27+
grant.openid_connect_nonce = nil
28+
subject.send :after_successful_response
29+
30+
expect(response.id_token.nonce).to be_nil
31+
end
2132
end
2233
end

0 commit comments

Comments
 (0)