-module(flwr_oauth2@revocation). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/flwr_oauth2/revocation.gleam"). -export([to_http_request/1, parse_revocation_response/1]). -export_type([revocation_request/0, token_type_hint/0, revocation_response/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 implements [RFC7009](https://datatracker.ietf.org/doc/html/rfc7009) for OAuth 2.0 token revocation.\n" " It offers functions to revoke provided tokens, such as access and refresh tokens.\n" " Which token types are supported depends on the OAuth 2.0 server.\n" " If the server implements RFC7009 it must support revocation of refresh tokens and should support the revocation of access tokens.\n" ). -type revocation_request() :: {revocation_request, gleam@uri:uri(), binary(), gleam@option:option(token_type_hint()), flwr_oauth2@authentication:client_authentication()}. -type token_type_hint() :: access_token | refresh_token | {other, binary()}. -type revocation_response() :: revocation_response. -file("src/flwr_oauth2/revocation.gleam", 56). -spec type_hint(revocation_request()) -> gleam@option:option({binary(), binary()}). type_hint(Revocation_request) -> gleam@option:map( erlang:element(4, Revocation_request), fun(Hint) -> Token_type = case Hint of access_token -> <<"access_token"/utf8>>; refresh_token -> <<"refresh_token"/utf8>>; {other, Hint@1} -> Hint@1 end, {<<"token_type_hint"/utf8>>, Token_type} end ). -file("src/flwr_oauth2/revocation.gleam", 42). ?DOC(" Formats a revocation request into a valid gleam http request.\n"). -spec to_http_request(revocation_request()) -> {ok, gleam@http@request:request(binary())} | {error, flwr_oauth2@token_request:request_error()}. to_http_request(Revocation_request) -> Body = begin _pipe = [{<<"token"/utf8>>, erlang:element(3, Revocation_request)}], flwr_oauth2@helpers:add_if_present(_pipe, type_hint(Revocation_request)) end, flwr_oauth2@token_request:build_post_request( erlang:element(2, Revocation_request), Body, erlang:element(5, Revocation_request), [] ). -file("src/flwr_oauth2/revocation.gleam", 69). ?DOC( " Parses a revocation response as defined in [RFC7009](https://datatracker.ietf.org/doc/html/rfc7009#section-2.2).\n" " If the response status is 200 the body is ignored.\n" " Any other status code is an error response and will be parsed accordingly.\n" ). -spec parse_revocation_response(gleam@http@response:response(binary())) -> {ok, revocation_response()} | {error, flwr_oauth2@response:response_error()}. parse_revocation_response(Revocation_response) -> case erlang:element(2, Revocation_response) of 200 -> {ok, revocation_response}; _ -> _pipe = flwr_oauth2@response:parse_error_response( Revocation_response ), {error, _pipe} end.