diff options
author | Maksim <parallel588@gmail.com> | 2019-05-06 17:51:03 +0000 |
---|---|---|
committer | lambda <lain@soykaf.club> | 2019-05-06 17:51:03 +0000 |
commit | 1040caf096347b638b9fda5b23fcccde87b32ede (patch) | |
tree | db56c5118b7e853f27d5bd0d0782ab72f532d821 /lib/pleroma/web/oauth/token/utils.ex | |
parent | aacac9da0beddcf797958acca330747b8f2d1f06 (diff) | |
download | pleroma-1040caf096347b638b9fda5b23fcccde87b32ede.tar.gz |
fix format
Modified-by: Maksim Pechnikov <parallel588@gmail.com>
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 |