mirror of
https://github.com/team-alembic/ash_authentication.git
synced 2024-09-20 05:13:10 +12:00
fix: only use sign in token expiration for sign in tokens (#424)
This commit is contained in:
parent
0a089693e3
commit
62d458f629
3 changed files with 23 additions and 9 deletions
|
@ -24,7 +24,7 @@ defmodule AshAuthentication.GenerateTokenChange do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp generate_token(purpose, record, strategy)
|
defp generate_token(purpose, record, strategy)
|
||||||
when purpose in [:user, :sign_in] and is_integer(strategy.sign_in_token_lifetime) do
|
when is_integer(strategy.sign_in_token_lifetime) and purpose == :sign_in do
|
||||||
{:ok, token, _claims} =
|
{:ok, token, _claims} =
|
||||||
Jwt.token_for_user(record, %{"purpose" => to_string(purpose)},
|
Jwt.token_for_user(record, %{"purpose" => to_string(purpose)},
|
||||||
token_lifetime: strategy.sign_in_token_lifetime
|
token_lifetime: strategy.sign_in_token_lifetime
|
||||||
|
|
|
@ -14,7 +14,7 @@ defmodule AshAuthentication.Strategy.Password.SignInPreparation do
|
||||||
"""
|
"""
|
||||||
use Ash.Resource.Preparation
|
use Ash.Resource.Preparation
|
||||||
alias AshAuthentication.{Errors.AuthenticationFailed, Info, Jwt}
|
alias AshAuthentication.{Errors.AuthenticationFailed, Info, Jwt}
|
||||||
alias Ash.{Error.Unknown, Query, Resource, Resource.Preparation}
|
alias Ash.{Error.Unknown, Query, Resource.Preparation}
|
||||||
require Ash.Query
|
require Ash.Query
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
|
@ -112,14 +112,25 @@ defmodule AshAuthentication.Strategy.Password.SignInPreparation do
|
||||||
|
|
||||||
defp maybe_generate_token(purpose, record, strategy) when purpose in [:user, :sign_in] do
|
defp maybe_generate_token(purpose, record, strategy) when purpose in [:user, :sign_in] do
|
||||||
if AshAuthentication.Info.authentication_tokens_enabled?(record.__struct__) do
|
if AshAuthentication.Info.authentication_tokens_enabled?(record.__struct__) do
|
||||||
|
generate_token(purpose, record, strategy)
|
||||||
|
else
|
||||||
|
record
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp generate_token(purpose, record, strategy)
|
||||||
|
when is_integer(strategy.sign_in_token_lifetime) and purpose == :sign_in do
|
||||||
{:ok, token, _claims} =
|
{:ok, token, _claims} =
|
||||||
Jwt.token_for_user(record, %{"purpose" => to_string(purpose)},
|
Jwt.token_for_user(record, %{"purpose" => to_string(purpose)},
|
||||||
token_lifetime: strategy.sign_in_token_lifetime
|
token_lifetime: strategy.sign_in_token_lifetime
|
||||||
)
|
)
|
||||||
|
|
||||||
Resource.put_metadata(record, :token, token)
|
Ash.Resource.put_metadata(record, :token, token)
|
||||||
else
|
end
|
||||||
record
|
|
||||||
end
|
defp generate_token(purpose, record, _strategy) do
|
||||||
|
{:ok, token, _claims} = Jwt.token_for_user(record, %{"purpose" => to_string(purpose)})
|
||||||
|
|
||||||
|
Ash.Resource.put_metadata(record, :token, token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -295,7 +295,10 @@ defmodule AshAuthentication.UserIdentity.Transformer do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_destroy_action(_dsl_state, action_name) do
|
defp build_destroy_action(_dsl_state, action_name) do
|
||||||
Transformer.build_entity(Resource.Dsl, [:actions], :destroy, name: action_name, primary?: true)
|
Transformer.build_entity(Resource.Dsl, [:actions], :destroy,
|
||||||
|
name: action_name,
|
||||||
|
primary?: true
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp validate_destroy_action(dsl_state, action_name) do
|
defp validate_destroy_action(dsl_state, action_name) do
|
||||||
|
|
Loading…
Reference in a new issue