diff --git a/lib/ex_oauth2_provider/oauth2/token/strategy/client_credentials.ex b/lib/ex_oauth2_provider/oauth2/token/strategy/client_credentials.ex index 4da262bb..845fa958 100644 --- a/lib/ex_oauth2_provider/oauth2/token/strategy/client_credentials.ex +++ b/lib/ex_oauth2_provider/oauth2/token/strategy/client_credentials.ex @@ -38,13 +38,7 @@ defmodule ExOauth2Provider.Token.ClientCredentials do scopes: scopes } - application - |> AccessTokens.get_application_token_for(scopes, config) - |> case do - nil -> AccessTokens.create_application_token(application, token_params, config) - access_token -> {:ok, access_token} - end - |> case do + case AccessTokens.create_application_token(application, token_params, config) do {:ok, access_token} -> {:ok, Map.merge(params, %{access_token: access_token})} {:error, error} -> Error.add_error({:ok, params}, error) end diff --git a/test/ex_oauth2_provider/access_tokens/access_tokens_test.exs b/test/ex_oauth2_provider/access_tokens/access_tokens_test.exs index 1a71abe5..d292861c 100644 --- a/test/ex_oauth2_provider/access_tokens/access_tokens_test.exs +++ b/test/ex_oauth2_provider/access_tokens/access_tokens_test.exs @@ -116,31 +116,6 @@ defmodule ExOauth2Provider.AccessTokensTest do end end - describe "get_application_token_for/3" do - test "fetches", %{application: application} do - {:ok, access_token1} = AccessTokens.create_application_token(application, %{}, otp_app: :ex_oauth2_provider) - inserted_at = QueryHelpers.timestamp(OauthAccessToken, :inserted_at, seconds: -1) - QueryHelpers.change!(access_token1, inserted_at: inserted_at) - {:ok, access_token2} = AccessTokens.create_application_token(application, %{}, otp_app: :ex_oauth2_provider) - - assert %OauthAccessToken{id: id} = AccessTokens.get_application_token_for(application, nil, otp_app: :ex_oauth2_provider) - assert id == access_token2.id - - refute AccessTokens.get_application_token_for(Fixtures.application(uid: "application-2"), nil, otp_app: :ex_oauth2_provider) - end - - test "does not get the token when it expires within 5 minutes", %{application: application} do - {:ok, %{expires_in: expires_in} = access_token} = - AccessTokens.create_application_token(application, %{}, otp_app: :ex_oauth2_provider) - - inserted_at = QueryHelpers.timestamp(OauthAccessToken, :inserted_at, seconds: -1 * expires_in + 299) - # the token will expire in 4min 59s - QueryHelpers.change!(access_token, inserted_at: inserted_at) - - refute AccessTokens.get_application_token_for(application, nil, otp_app: :ex_oauth2_provider) - end - end - test "get_authorized_tokens_for/2", %{user: user, application: application} do {:ok, access_token} = AccessTokens.create_token(user, %{application: application}, otp_app: :ex_oauth2_provider)