Skip to content

Commit

Permalink
Enable to reuse_access_toke
Browse files Browse the repository at this point in the history
  • Loading branch information
yokozawa0701 committed Nov 6, 2023
1 parent ed1dcc2 commit 4931892
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ def by_previous_refresh_token(previous_refresh_token)
# @return [Doorkeeper::AccessToken, nil] Access Token instance or
# nil if matching record was not found
#
def matching_token_for(application, resource_owner, scopes)
def matching_token_for(application, resource_owner, scopes, include_expired: true)
tokens = authorized_tokens_for(application&.id, resource_owner)
tokens = tokens.not_expired unless include_expired
find_matching_token(tokens, application, scopes)
end

Expand Down Expand Up @@ -425,6 +426,30 @@ def token_generator
rescue NameError
raise Doorkeeper::Errors::TokenGeneratorNotFound, "#{generator_name} not found"
end

# Returns non-expired and non-revoked access tokens
def not_expired
relation = where(revoked_at: nil)

relation.where(
{
'$expr': {
'$gt': [
{
'$dateAdd': {
startDate: '$created_at',
unit: 'second',
amount: '$expires_in',
},
},
Time.now.utc,
],
},
}
).or(
relation.where(expires_in: nil)
)
end
end
end
end
Expand Down

0 comments on commit 4931892

Please sign in to comment.