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@http_headers.erl
Raw

src/flwr_oauth2@http_headers.erl

-module(flwr_oauth2@http_headers).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/flwr_oauth2/http_headers.gleam").
-export([encode_base64/2, set_basic/3, set_bearer/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Helper module to collect useful setters for HTTP headers, such as the authorization header.\n").
-file("src/flwr_oauth2/http_headers.gleam", 29).
-spec encode_base64(binary(), binary()) -> binary().
encode_base64(Client_id, Client_secret) ->
_pipe = (<<<<Client_id/binary, ":"/utf8>>/binary, Client_secret/binary>>),
_pipe@1 = gleam_stdlib:identity(_pipe),
gleam_stdlib:base64_encode(_pipe@1, true).
-file("src/flwr_oauth2/http_headers.gleam", 17).
-spec set_basic(gleam@http@request:request(FOT), binary(), binary()) -> gleam@http@request:request(FOT).
set_basic(Req, Client_id, Client_secret) ->
_pipe = Req,
gleam@http@request:set_header(
_pipe,
<<"Authorization"/utf8>>,
<<"Basic "/utf8, (encode_base64(Client_id, Client_secret))/binary>>
).
-file("src/flwr_oauth2/http_headers.gleam", 9).
-spec set_bearer(gleam@http@request:request(FOQ), binary()) -> gleam@http@request:request(FOQ).
set_bearer(Req, Bearer_token) ->
_pipe = Req,
gleam@http@request:set_header(
_pipe,
<<"authorization"/utf8>>,
<<"Bearer "/utf8, Bearer_token/binary>>
).