Skip to content

Commit

Permalink
bug: Don't require nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
toupeira committed Nov 5, 2016
1 parent fb32621 commit d2945da
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/doorkeeper/openid_connect/oauth/authorization/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ module Authorization
module Code
def issue_token
super.tap do |access_grant|
::Doorkeeper::OpenidConnect::Nonce.create!(
access_grant: access_grant,
nonce: pre_auth.nonce
)
if pre_auth.nonce
::Doorkeeper::OpenidConnect::Nonce.create!(
access_grant: access_grant,
nonce: pre_auth.nonce
)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module AuthorizationCodeRequest

def after_successful_response
super
id_token = Doorkeeper::OpenidConnect::Models::IdToken.new(access_token, grant.openid_connect_nonce.use!)
id_token = Doorkeeper::OpenidConnect::Models::IdToken.new(access_token, grant.openid_connect_nonce.try(:use!))
@response.id_token = id_token
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/oauth/authorization/code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
})
end

it 'does not store the nonce if not present' do
allow(pre_auth).to receive(:nonce) { nil }
subject.issue_token

expect(Doorkeeper::OpenidConnect::Nonce).to_not have_received(:create!)
end

it 'returns the created grant' do
expect(subject.issue_token).to be_a Doorkeeper::AccessGrant
end
Expand Down
17 changes: 14 additions & 3 deletions spec/lib/oauth/authorization_code_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require 'rails_helper'

describe Doorkeeper::OpenidConnect::OAuth::AuthorizationCodeRequest do
subject { Doorkeeper::OAuth::AuthorizationCodeRequest.new server, grant, client }
subject {
Doorkeeper::OAuth::AuthorizationCodeRequest.new(server, grant, client).tap do |request|
request.instance_variable_set '@response', response
request.access_token = token
end
}

let(:server) { double }
let(:client) { double }
let(:grant) { create :access_grant, openid_connect_nonce: nonce }
Expand All @@ -11,12 +17,17 @@

describe '#after_successful_response' do
it 'adds the ID token to the response' do
subject.instance_variable_set '@response', response
subject.access_token = token
subject.send :after_successful_response

expect(response.id_token).to be_a Doorkeeper::OpenidConnect::Models::IdToken
expect(response.id_token.nonce).to eq '123456'
end

it 'skips the nonce if not present' do
grant.openid_connect_nonce = nil
subject.send :after_successful_response

expect(response.id_token.nonce).to be_nil
end
end
end

0 comments on commit d2945da

Please sign in to comment.