diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2019-05-14 19:00:07 +0700 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2019-05-14 19:00:07 +0700 |
commit | e82e73478e577782407bc8452d17925675d99d10 (patch) | |
tree | 0784beff0a57cbeb239215314e0436b7f0a5253f /lib/pleroma/web/oauth/token/utils.ex | |
parent | 23276e8d6848fa8eae390c16b6e0619c12546e4a (diff) | |
parent | cdcdbd88da76f18c21da7f6f15a29883044902c8 (diff) | |
download | pleroma-e82e73478e577782407bc8452d17925675d99d10.tar.gz |
Merge remote-tracking branch 'pleroma/develop' into feature/addressable-lists
Diffstat (limited to 'lib/pleroma/web/oauth/token/utils.ex')
-rw-r--r-- | lib/pleroma/web/oauth/token/utils.ex | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/pleroma/web/oauth/token/utils.ex b/lib/pleroma/web/oauth/token/utils.ex new file mode 100644 index 000000000..a81560a1c --- /dev/null +++ b/lib/pleroma/web/oauth/token/utils.ex @@ -0,0 +1,30 @@ +defmodule Pleroma.Web.OAuth.Token.Utils do + @moduledoc """ + Auxiliary functions for dealing with tokens. + """ + + @doc "convert token inserted_at to unix timestamp" + def format_created_at(%{inserted_at: inserted_at} = _token) do + inserted_at + |> DateTime.from_naive!("Etc/UTC") + |> DateTime.to_unix() + end + + @doc false + @spec generate_token(keyword()) :: binary() + def generate_token(opts \\ []) do + opts + |> Keyword.get(:size, 32) + |> :crypto.strong_rand_bytes() + |> Base.url_encode64(padding: false) + end + + # XXX - for whatever reason our token arrives urlencoded, but Plug.Conn should be + # decoding it. Investigate sometime. + def fix_padding(token) do + token + |> URI.decode() + |> Base.url_decode64!(padding: false) + |> Base.url_encode64(padding: false) + end +end |