Supabase. Auth. Schemas. OAuth. Grant
(supabase_auth v1.0.1)
View Source
Schema for OAuth grant representation using schemaless changesets.
OAuth grants represent user authorization to a third-party client application.
Summary
Functions
Parses OAuth grant data from API response.
Parses a list of OAuth grants from API response.
Types
@type t() :: %{ client: Supabase.Auth.Schemas.OAuth.Client.t(), scopes: [String.t()], granted_at: String.t() }
Functions
@spec parse(map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Parses OAuth grant data from API response.
Returns {:ok, map} with parsed grant data or {:error, changeset} if validation fails.
Examples
iex> Grant.parse(%{
...> "client" => %{
...> "id" => "client-123",
...> "name" => "My App",
...> "uri" => "https://example.com"
...> },
...> "scopes" => ["read", "write"],
...> "granted_at" => "2024-01-01T00:00:00Z"
...> })
{:ok, %{
client: %{id: "client-123", name: "My App", uri: "https://example.com", logo_uri: nil},
scopes: ["read", "write"],
granted_at: "2024-01-01T00:00:00Z"
}}
iex> Grant.parse(%{})
{:error, %Ecto.Changeset{}}
Parses a list of OAuth grants from API response.
Returns {:ok, [grant_map]} with a list of parsed grants or {:error, reason} if any grant fails to parse.
Examples
iex> Grant.parse_list([
...> %{"client" => %{"id" => "c1", "name" => "App 1", "uri" => "https://app1.com"}, "scopes" => ["read"], "granted_at" => "2024-01-01T00:00:00Z"},
...> %{"client" => %{"id" => "c2", "name" => "App 2", "uri" => "https://app2.com"}, "scopes" => ["write"], "granted_at" => "2024-01-02T00:00:00Z"}
...> ])
{:ok, [%{client: %{...}, scopes: ["read"], ...}, %{client: %{...}, scopes: ["write"], ...}]}