apiac v1.0.0 APIac View Source
Convenience functions to work with APIac and API requests
Link to this section Summary
Functions
Returns true
if the connection is authenticated by an APIac plug, false
otherwise
Returns the APIac.Authenticator
that has authenticated the connection, nil
if none has
Returns the name of the client, or nil
if the connection is unauthenticated
Returns the following error response verbosity level depending on the environment
Returns true
if this is a machine-to-machine authentication (i.e. no subject involved), false
otherwise
Returns metadata associated with the authenticated connection, or nil
if there's none
Returns true
if the input string is an rfc7230 quoted-string, false
otherwise
Returns true
if the input string is an rfc7230 token, false
otherwise
Returns true
if the input string is an rfc7235 token68, false
otherwise
Sets the HTTP WWW-Authenticate header of a Plug.Conn
and returns it.
Returns the name of the subject, or nil
if it was not set (unauthenticated connection, machine-tomachine authentication...)
Returns true
if the authentication is on behalf of a real user (the subject), false
otherwise
Link to this section Types
Link to this section Functions
Returns true
if the connection is authenticated by an APIac plug, false
otherwise
Returns the APIac.Authenticator
that has authenticated the connection, nil
if none has
Returns the name of the client, or nil
if the connection is unauthenticated
default_error_response_verbosity(conn)
View Sourcedefault_error_response_verbosity(Plug.Conn.t()) :: :debug | :normal | :minimal
Returns the following error response verbosity level depending on the environment:
- dev:
:debug
- test:
:normal
- prod:
:normal
It uses the APIac configuration key :env
that is by defaults executed to Mix.env()
machine_to_machine?(conn)
View Sourcemachine_to_machine?(Plug.Conn.t()) :: boolean()
Returns true
if this is a machine-to-machine authentication (i.e. no subject involved), false
otherwise
metadata(arg1)
View Sourcemetadata(Plug.Conn.t()) :: %{required(String.t()) => String.t()} | nil
Returns metadata associated with the authenticated connection, or nil
if there's none
Returns true
if the input string is an rfc7230 quoted-string, false
otherwise
Returns true
if the input string is an rfc7230 token, false
otherwise
Returns true
if the input string is an rfc7235 token68, false
otherwise
set_WWWauthenticate_challenge(conn, scheme, params)
View Sourceset_WWWauthenticate_challenge(Plug.Conn.t(), http_authn_scheme(), %{ required(String.t()) => String.t() }) :: Plug.Conn.t()
Sets the HTTP WWW-Authenticate header of a Plug.Conn
and returns it.
Note that the parameters are passed as a map whose:
- keys are rfc7230 tokens
- values are rfc7230 quoted-strings, but without the enclosing quotes: they are mandatory and therefore added automatically
Examples
iex> conn(:get, "/ressource") |>
...> Plug.Conn.put_status(:unauthorized) |>
...> APIac.set_WWWauthenticate_challenge("Basic", %{"realm" => "realm_1"}) |>
...> APIac.set_WWWauthenticate_challenge("Bearer", %{"realm" => "realm_1", "error" => "insufficient_scope", "scope" => "group:read group:write"})
%Plug.Conn{
adapter: {Plug.Adapters.Test.Conn, :...},
assigns: %{},
before_send: [],
body_params: %Plug.Conn.Unfetched{aspect: :body_params},
cookies: %Plug.Conn.Unfetched{aspect: :cookies},
halted: false,
host: "www.example.com",
method: "GET",
owner: #PID<0.202.0>,
params: %Plug.Conn.Unfetched{aspect: :params},
path_info: ["ressource"],
path_params: %{},
peer: {{127, 0, 0, 1}, 111317},
port: 80,
private: %{},
query_params: %Plug.Conn.Unfetched{aspect: :query_params},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
req_headers: [],
request_path: "/ressource",
resp_body: nil,
resp_cookies: %{},
resp_headers: [
{"cache-control", "max-age=0, private, must-revalidate"},
{"www-authenticate",
"Basic realm="realm_1", Bearer error="insufficient_scope", realm="realm_1", scope="group:read group:write""}
],
scheme: :http,
script_name: [],
secret_key_base: nil,
state: :unset,
status: 401
}
Returns the name of the subject, or nil
if it was not set (unauthenticated connection, machine-tomachine authentication...)
subject_authenticated?(arg1)
View Sourcesubject_authenticated?(Plug.Conn.t()) :: boolean()
Returns true
if the authentication is on behalf of a real user (the subject), false
otherwise