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

src/flwr_oauth2@jwt_profile.erl

-module(flwr_oauth2@jwt_profile).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/flwr_oauth2/jwt_profile.gleam").
-export([to_http_request/1]).
-export_type([jwt_authorization_grant_request/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.
?MODULEDOC(
" This module aims to implement [RFC7523](https://datatracker.ietf.org/doc/html/rfc7523) JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants.\n"
" For more infomation on the Authorization Assertion Grant Type see [RFC7521](https://datatracker.ietf.org/doc/html/).\n"
).
-type jwt_authorization_grant_request() :: {jwt_authorization_grant_request,
gleam@uri:uri(),
binary(),
gleam@option:option(flwr_oauth2:client_authentication()),
list(binary())}.
-file("src/flwr_oauth2/jwt_profile.gleam", 32).
-spec authorization_setter(
gleam@option:option(flwr_oauth2:client_authentication())
) -> flwr_oauth2:authorization_setter().
authorization_setter(Authorization) ->
_pipe = Authorization,
_pipe@1 = gleam@option:map(_pipe, fun flwr_oauth2:authorization_setter/1),
gleam@option:unwrap(
_pipe@1,
{authorization_setter, fun(Req) -> {ok, Req} end}
).
-file("src/flwr_oauth2/jwt_profile.gleam", 20).
-spec to_http_request(jwt_authorization_grant_request()) -> {ok,
gleam@http@request:request(binary())} |
{error, flwr_oauth2:request_error()}.
to_http_request(Grant) ->
_pipe = [{<<"grant_type"/utf8>>,
<<"urn:ietf:params:oauth:grant-type:jwt-bearer"/utf8>>},
{<<"assertion"/utf8>>, erlang:element(3, Grant)}],
_pipe@1 = flwr_oauth2:add_scope(_pipe, erlang:element(5, Grant)),
flwr_oauth2:setup_request(
erlang:element(2, Grant),
_pipe@1,
begin
_pipe@2 = erlang:element(4, Grant),
authorization_setter(_pipe@2)
end
).