diff --git a/lib/ex_oauth2_provider/access_tokens/access_tokens.ex b/lib/ex_oauth2_provider/access_tokens/access_tokens.ex index f95a17b..c129e3a 100644 --- a/lib/ex_oauth2_provider/access_tokens/access_tokens.ex +++ b/lib/ex_oauth2_provider/access_tokens/access_tokens.ex @@ -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 @@ -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)