defmodule AshAuthentication.Phoenix.Components.OAuth2 do use AshAuthentication.Phoenix.Overrides.Overridable, root_class: "CSS classes for the root `div` element.", link_class: "CSS classes for the `a` element.", icon_class: "CSS classes for the icon SVG." @moduledoc """ Generates a sign-in button for OAuth2. ## Component hierarchy This is the top-most strategy-specific component, nested below `AshAuthentication.Phoenix.Components.SignIn`. ## Props * `strategy` - The strategy configuration as per `AshAuthentication.Info.strategy/2`. Required. * `overrides` - A list of override modules. #{AshAuthentication.Phoenix.Overrides.Overridable.generate_docs()} """ use AshAuthentication.Phoenix.Web, :live_component alias AshAuthentication.{Info, Strategy} alias Phoenix.LiveView.Rendered import AshAuthentication.Phoenix.Components.Helpers, only: [route_helpers: 1] import Phoenix.HTML, only: [raw: 1] import PhoenixHTMLHelpers.Form, only: [humanize: 1] @type props :: %{ required(:strategy) => AshAuthentication.Strategy.t(), optional(:overrides) => [module] } @doc false @impl true @spec render(props) :: Rendered.t() | no_return def render(assigns) do assigns = assigns |> assign(:subject_name, Info.authentication_subject_name!(assigns.strategy.resource)) |> assign_new(:overrides, fn -> [AshAuthentication.Phoenix.Overrides.Default] end) ~H"""
""" end def icon(assigns) do ~H""" <%= if @icon do %> <%= raw(icon_svg(@icon, override_for(@overrides, :icon_class))) %> <% end %> """ end defp icon_svg(:auth0, class), do: ~s""" """ defp icon_svg(:github, class), do: ~s""" """ defp icon_svg(:oidc, class), do: ~s""" """ defp icon_svg(_, class), do: ~s""" """ defp strategy_name(strategy) do case Strategy.name(strategy) do :oauth2 -> "OAuth" other -> humanize(other) end end end