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

Configuration per IdToken expiration #209

Open
wants to merge 1 commit into
base: master
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
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