diff options
author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-12-09 21:14:39 +0300 |
---|---|---|
committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-12-09 21:14:39 +0300 |
commit | 7fff9c1bee009c7b05679ad8bd57de8bcf58e610 (patch) | |
tree | 9bf864f2d4af7b2df3055c8c38a56de3376fccec /lib/pleroma/web/o_auth/token.ex | |
parent | c308224aafff4ca5bcbb481930f1eb557ab6ea6d (diff) | |
download | pleroma-7fff9c1bee009c7b05679ad8bd57de8bcf58e610.tar.gz |
Tweaks to OAuth entities expiration: changed default to 30 days, removed hardcoded values usage, fixed OAuthView (expires_in).
Diffstat (limited to 'lib/pleroma/web/o_auth/token.ex')
-rw-r--r-- | lib/pleroma/web/o_auth/token.ex | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/pleroma/web/o_auth/token.ex b/lib/pleroma/web/o_auth/token.ex index 9170a7ec7..886117d15 100644 --- a/lib/pleroma/web/o_auth/token.ex +++ b/lib/pleroma/web/o_auth/token.ex @@ -27,6 +27,10 @@ defmodule Pleroma.Web.OAuth.Token do timestamps() end + def lifespan do + Pleroma.Config.get!([:oauth2, :token_expires_in]) + end + @doc "Gets token by unique access token" @spec get_by_token(String.t()) :: {:ok, t()} | {:error, :not_found} def get_by_token(token) do @@ -83,11 +87,11 @@ defmodule Pleroma.Web.OAuth.Token do end defp put_valid_until(changeset, attrs) do - expires_in = - Map.get(attrs, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), expires_in())) + valid_until = + Map.get(attrs, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), lifespan())) changeset - |> change(%{valid_until: expires_in}) + |> change(%{valid_until: valid_until}) |> validate_required([:valid_until]) end @@ -138,6 +142,4 @@ defmodule Pleroma.Web.OAuth.Token do end def is_expired?(_), do: false - - defp expires_in, do: Pleroma.Config.get([:oauth2, :token_expires_in], 600) end |