Packages

A small, focused OAuth 2.0 library for Gleam, built on top of Gleams HTTP requests and responses.

Current section

Files

Jump to
flwr_oauth2 src flwr_oauth2@common.erl
Raw

src/flwr_oauth2@common.erl

-module(flwr_oauth2@common).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/flwr_oauth2/common.gleam").
-export([secret_is_valid/1, is_secret_invalid/1, parse_scope/1]).
-export_type([secret/0, client_id/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type secret() :: {secret, binary()} |
{secret_with_expiration, binary(), gleam@time@timestamp:timestamp()}.
-type client_id() :: {client_id, binary()}.
-file("src/flwr_oauth2/common.gleam", 33).
?DOC(
" Checks if a given secret is not expired.\n"
" Returns always true for secrets that cannot expire.\n"
).
-spec secret_is_valid(secret()) -> boolean().
secret_is_valid(Secret) ->
_pipe = case Secret of
{secret, _} ->
true;
{secret_with_expiration, _, Expires_at} ->
gleam@time@timestamp:compare(
Expires_at,
gleam@time@timestamp:system_time()
)
=:= lt
end,
gleam@bool:negate(_pipe).
-file("src/flwr_oauth2/common.gleam", 44).
?DOC(
" Checks if a given secret is expired.\n"
" Returns always false for secrets that cannot expire.\n"
).
-spec is_secret_invalid(secret()) -> boolean().
is_secret_invalid(Secret) ->
case Secret of
{secret, _} ->
false;
{secret_with_expiration, _, _} ->
_pipe = Secret,
_pipe@1 = secret_is_valid(_pipe),
gleam@bool:negate(_pipe@1)
end.
-file("src/flwr_oauth2/common.gleam", 64).
-spec string_not_empty(binary()) -> boolean().
string_not_empty(L) ->
not gleam@string:is_empty(L).
-file("src/flwr_oauth2/common.gleam", 57).
?DOC(
" Parses a string containing the space separated scopes.\n"
"\n"
" ## Example\n"
" ```gleam\n"
" parse_scope(\"scope1 scope2\")\n"
" ````\n"
).
-spec parse_scope(binary()) -> list(binary()).
parse_scope(Scope) ->
_pipe = Scope,
_pipe@1 = gleam@string:trim(_pipe),
_pipe@2 = gleam@string:split(_pipe@1, <<" "/utf8>>),
gleam@list:filter(_pipe@2, fun string_not_empty/1).