Skip to content

Commit

Permalink
Configuration per IdToken expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
martinezcoder committed Jul 26, 2024
1 parent ab28ba3 commit 5e2d406
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/doorkeeper/openid_connect/id_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class IdToken

attr_reader :nonce

def initialize(access_token, nonce = nil)
def initialize(access_token, nonce = nil, expires_in = Doorkeeper::OpenidConnect.configuration.expiration)
@access_token = access_token
@nonce = nonce
@resource_owner = Doorkeeper::OpenidConnect.configuration.resource_owner_from_access_token.call(access_token)
@issued_at = Time.zone.now
@expires_in = expires_in
end

def claims
Expand Down Expand Up @@ -57,7 +58,7 @@ def audience
end

def expiration
(@issued_at.utc + Doorkeeper::OpenidConnect.configuration.expiration).to_i
(@issued_at.utc + @expires_in).to_i
end

def issued_at
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/id_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
)
end

context 'when expires_in is specified for the token' do
subject { described_class.new(access_token, nonce, expires_in) }

let(:expires_in) { 10 }

it 'returns expiration claim with the specified value' do
expect(subject.claims[:exp]).to eq(subject.claims[:iat] + expires_in)
end
end

context 'when application is not set on the access token' do
before do
access_token.application = nil
Expand Down

0 comments on commit 5e2d406

Please sign in to comment.