View Source CloudflareAccessEx.Principal (cloudflare_access_ex v0.1.2)
Defines the Principal
struct for representing the principal identity of a user coming through Cloudflare Access.
A Principal
can either represent an anonymous user or a user that has logged in through an identity provider (IdP).
The struct differentiates between these two states with the :type
field, which can be :anonymous
for users without
a user ID or email, or :authenticated
for users who have been verified and have these attributes.
Summary
Functions
Creates a Principal
struct for an anonymous user.
Creates a Principal
struct for an authenticated user with the provided user_id
and email
.
Types
@type anonymous_principal() :: %CloudflareAccessEx.Principal{
email: nil,
type: :anonymous,
user_id: nil
}
@type t() :: anonymous_principal() | authenticated_principal()
Functions
@spec anonymous() :: anonymous_principal()
Creates a Principal
struct for an anonymous user.
Examples
iex> CloudflareAccessEx.Principal.anonymous()
%CloudflareAccessEx.Principal{type: :anonymous, user_id: nil, email: nil}
@spec authenticated(String.t(), String.t()) :: authenticated_principal()
Creates a Principal
struct for an authenticated user with the provided user_id
and email
.
Parameters
user_id
: The user ID from the IdP.email
: The email address associated with the user.
Examples
iex> CloudflareAccessEx.Principal.authenticated("user123", "user@example.com")
%CloudflareAccessEx.Principal{
type: :authenticated,
user_id: "user123",
email: "user@example.com"
}