Arc.Principal (cratis_arc v0.1.0)

Copy Markdown View Source

The authenticated caller of a command or query.

Built by an Arc.Authentication handler from whatever your application already uses to authenticate (phx.gen.auth, a token plug, a reverse proxy). Arc never invents a second authentication system.

Summary

Functions

Whether another identity is acting on behalf of this principal.

The identity acting on behalf of this principal, or nil.

The anonymous principal.

Whether the principal has at least one of the given roles.

Builds an authenticated principal.

Types

t()

@type t() :: %Arc.Principal{
  actor: t() | nil,
  authenticated?: boolean(),
  claims: %{optional(String.t()) => String.t() | [String.t()]},
  id: String.t() | nil,
  name: String.t() | nil,
  roles: [String.t()]
}

Functions

acted_on_behalf_of?(principal)

@spec acted_on_behalf_of?(t()) :: boolean()

Whether another identity is acting on behalf of this principal.

In an on-behalf session the principal is the represented user (who decides what the request may do) and actor is who is actually acting. roles never include the actor's roles.

actor(principal)

@spec actor(t()) :: t() | nil

The identity acting on behalf of this principal, or nil.

anonymous()

@spec anonymous() :: t()

The anonymous principal.

in_any_role?(principal, wanted)

@spec in_any_role?(t(), [String.t()]) :: boolean()

Whether the principal has at least one of the given roles.

new(id, name, opts \\ [])

@spec new(String.t(), String.t(), keyword()) :: t()

Builds an authenticated principal.