Skip to content

Commit

Permalink
revert the 5 minute check on fetching tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
tarzan committed Feb 19, 2024
1 parent 971f1f9 commit 3891776
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions lib/ex_oauth2_provider/access_tokens/access_tokens.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,6 @@ defmodule ExOauth2Provider.AccessTokens do
|> load_matching_token_for(application, scopes, config)
end

@doc """
Gets the most recent, acccessible, matching access token for an application.
## Examples
iex> get_application_token_for(application, "read write", otp_app: :my_app)
%OauthAccessToken{}
iex> get_application_token_for(application, "read invalid", otp_app: :my_app)
nil
"""
@spec get_application_token_for(Application.t(), binary(), keyword()) :: AccessToken.t() | nil
def get_application_token_for(application, scopes, config \\ []) do
config
|> Config.access_token()
|> scope_belongs_to(:resource_owner_id, nil)
|> scope_belongs_to(:application_id, application)
|> load_matching_token_for(application, scopes, config)
end

defp load_matching_token_for(queryable, application, scopes, config) do
now =
config
Expand All @@ -120,7 +100,7 @@ defmodule ExOauth2Provider.AccessTokens do

queryable
|> where([a], is_nil(a.revoked_at))
|> where([a], is_nil(a.expires_in) or datetime_add(a.inserted_at, a.expires_in, "second") > datetime_add(^now, 5, "minute"))
|> where([a], is_nil(a.expires_in) or datetime_add(a.inserted_at, a.expires_in, "second") > ^now
|> order_by([a], desc: a.inserted_at, desc: :id)
|> Config.repo(config).all()
|> Enum.filter(&is_accessible?/1)
Expand Down

0 comments on commit 3891776

Please sign in to comment.