From 5a76ce578361f79db6fc26833fc884c956b6a88c Mon Sep 17 00:00:00 2001 From: James Harton Date: Fri, 16 Dec 2022 15:21:54 +1300 Subject: [PATCH] feat: Add Auth0 icon. --- .../components/oauth2.ex | 29 ++++++++++++++++++- .../overrides/default.ex | 3 ++ mix.exs | 2 +- mix.lock | 8 ++--- test/support/accounts/user.ex | 8 +---- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lib/ash_authentication_phoenix/components/oauth2.ex b/lib/ash_authentication_phoenix/components/oauth2.ex index 1ac3cad..e49444e 100644 --- a/lib/ash_authentication_phoenix/components/oauth2.ex +++ b/lib/ash_authentication_phoenix/components/oauth2.ex @@ -1,7 +1,8 @@ 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." + link_class: "CSS classes for the `a` element.", + icon_class: "CSS classes for the icon SVG." @moduledoc """ Generates a sign-in button for OAuth2. @@ -24,6 +25,7 @@ defmodule AshAuthentication.Phoenix.Components.OAuth2 do alias AshAuthentication.Info alias Phoenix.LiveView.Rendered import AshAuthentication.Phoenix.Components.Helpers, only: [route_helpers: 1] + import Phoenix.HTML import Phoenix.HTML.Form @type props :: %{ @@ -50,12 +52,37 @@ defmodule AshAuthentication.Phoenix.Components.OAuth2 do } class={override_for(@overrides, :link_class)} > + <.icon icon={@strategy.icon} overrides={@overrides} /> Sign in with <%= strategy_name(@strategy) %> """ 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 strategy_name(strategy) do case strategy.name do :oauth2 -> "OAuth" diff --git a/lib/ash_authentication_phoenix/overrides/default.ex b/lib/ash_authentication_phoenix/overrides/default.ex index 0b6fc55..26b750e 100644 --- a/lib/ash_authentication_phoenix/overrides/default.ex +++ b/lib/ash_authentication_phoenix/overrides/default.ex @@ -134,6 +134,9 @@ defmodule AshAuthentication.Phoenix.Overrides.Default do w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-black bg-gray-200 hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 + inline-flex items-center """ + + set :icon_class, "-ml-0.4 mr-2 h-4 w-4" end end diff --git a/mix.exs b/mix.exs index 7cdc874..ca73861 100644 --- a/mix.exs +++ b/mix.exs @@ -89,7 +89,7 @@ defmodule AshAuthentication.Phoenix.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ash_authentication, "~> 3.1"}, + {:ash_authentication, "~> 3.2.1"}, {:ash_phoenix, "~> 1.1"}, {:ash, "~> 2.2"}, {:jason, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index 657ec54..99b1370 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,6 @@ %{ - "ash": {:hex, :ash, "2.4.25", "acb6b3679ebb57fcb50f317ad61e97aed67bddb4526cb64ad81434b79b50ad84", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, "~> 0.2.18", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d9e3e0ff891703b5aa8941bccfcb55e552de6b909a5d3662f6117b9ec520b489"}, - "ash_authentication": {:hex, :ash_authentication, "3.1.0", "b6f30a2f1107de113b56e1a29889e385acbccc62cea37dcf2f3a453477396a7a", [:mix], [{:ash, "~> 2.4", [hex: :ash, repo: "hexpm", optional: false]}, {:assent, "~> 0.2", [hex: :assent, repo: "hexpm", optional: false]}, {:bcrypt_elixir, "~> 3.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: false]}, {:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.5", [hex: :joken, repo: "hexpm", optional: false]}, {:mint, "~> 1.4", [hex: :mint, repo: "hexpm", optional: false]}, {:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}, {:spark, "~> 0.2.12", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "4cbf27735037cec0d63745a3081d285f71ff873c990871afcea64049b3dc06ff"}, + "ash": {:hex, :ash, "2.4.26", "b5b3821c77d274a0dc7bfd451b7cc759122306913b0fc2389bdea96a1425765d", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, "~> 0.3", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a5be0841ddb577dbbb3f17637ae3652e0a2edcbf7b3a9b916d0976c60458c9c8"}, + "ash_authentication": {:hex, :ash_authentication, "3.2.1", "b2a10cedb7ca8bc2cf8d9bb76b1cf090d5178e49eea711f1936e0317f6df932d", [:mix], [{:ash, "~> 2.4", [hex: :ash, repo: "hexpm", optional: false]}, {:assent, "~> 0.2", [hex: :assent, repo: "hexpm", optional: false]}, {:bcrypt_elixir, "~> 3.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: false]}, {:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.5", [hex: :joken, repo: "hexpm", optional: false]}, {:mint, "~> 1.4", [hex: :mint, repo: "hexpm", optional: false]}, {:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}, {:spark, "~> 0.3", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "b01fe2c34dbbc63e1bd2a84a27789c1a87b276177dadf9e6928f293309b0b11f"}, "ash_phoenix": {:hex, :ash_phoenix, "1.1.2", "36c46852fa0e739d7217092ac71e3a72e729d5c00758f401234215d8d32f350b", [:mix], [{:ash, "~> 2.0", [hex: :ash, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.5.6 or ~> 1.6", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.15", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "9afb2c9e8dbb68d3549713b4a96b56801c250489efdf4776b931770bd629e0bd"}, "assent": {:hex, :assent, "0.2.1", "46ad0ed92b72330f38c60bc03c528e8408475dc386f48d4ecd18833cfa581b9f", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, ">= 0.0.0", [hex: :certifi, repo: "hexpm", optional: true]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: true]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:ssl_verify_fun, ">= 0.0.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: true]}], "hexpm", "58c558b6029ffa287e15b38c8e07cd99f0b24e4846c52abad0c0a6225c4873bc"}, "bcrypt_elixir": {:hex, :bcrypt_elixir, "3.0.1", "9be815469e6bfefec40fa74658ecbbe6897acfb57614df1416eeccd4903f602c", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "486bb95efb645d1efc6794c1ddd776a186a9a713abf06f45708a6ce324fb96cf"}, @@ -38,7 +38,7 @@ "mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"}, "mimic": {:hex, :mimic, "1.7.4", "cd2772ffbc9edefe964bc668bfd4059487fa639a5b7f1cbdf4fd22946505aa4f", [:mix], [], "hexpm", "437c61041ecf8a7fae35763ce89859e4973bb0666e6ce76d75efc789204447c3"}, "mint": {:hex, :mint, "1.4.2", "50330223429a6e1260b2ca5415f69b0ab086141bc76dc2fbf34d7c389a6675b2", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "ce75a5bbcc59b4d7d8d70f8b2fc284b1751ffb35c7b6a6302b5192f8ab4ddd80"}, - "nimble_options": {:hex, :nimble_options, "0.5.1", "5c166f7669e40333191bea38e3bd3811cc13f459f1e4be49e89128a21b5d8c4d", [:mix], [], "hexpm", "d176cf7baa4fef0ceb301ca3eb8b55bd7de3e45f489c4f8b4f2849f1f114ef3e"}, + "nimble_options": {:hex, :nimble_options, "0.5.2", "42703307b924880f8c08d97719da7472673391905f528259915782bb346e0a1b", [:mix], [], "hexpm", "4da7f904b915fd71db549bcdc25f8d56f378ef7ae07dc1d372cbe72ba950dce0"}, "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, "phoenix": {:hex, :phoenix, "1.6.15", "0a1d96bbc10747fd83525370d691953cdb6f3ccbac61aa01b4acb012474b047d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d70ab9fbf6b394755ea88b644d34d79d8b146e490973151f248cacd122d20672"}, "phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"}, @@ -54,7 +54,7 @@ "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, "slugify": {:hex, :slugify, "1.3.1", "0d3b8b7e5c1eeaa960e44dce94382bee34a39b3ea239293e457a9c5b47cc6fd3", [:mix], [], "hexpm", "cb090bbeb056b312da3125e681d98933a360a70d327820e4b7f91645c4d8be76"}, "sourceror": {:hex, :sourceror, "0.11.2", "549ce48be666421ac60cfb7f59c8752e0d393baa0b14d06271d3f6a8c1b027ab", [:mix], [], "hexpm", "9ab659118896a36be6eec68ff7b0674cba372fc8e210b1e9dc8cf2b55bb70dfb"}, - "spark": {:hex, :spark, "0.2.18", "4f0bc3860682317911d10aee97c4818d3d5ed700f646a87ee1ea6e4a65650f33", [:mix], [{:nimble_options, "~> 0.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "fc2c0bb7556cfa60c97b7bdf9f83ef85b366ba697a006abe3083dccb0a6adf88"}, + "spark": {:hex, :spark, "0.3.0", "86a56daf6a433f7d135f5e17eeecc8684e39ade1095fcce0e6e98c2ec557dffd", [:mix], [{:nimble_options, "~> 0.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "16d03b802a39cea482cb7972d820c152ff8dd71c8445f1a0c1bc97cee1388d0a"}, "stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"}, "telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"}, "typable": {:hex, :typable, "0.3.0", "0431e121d124cd26f312123e313d2689b9a5322b15add65d424c07779eaa3ca1", [:mix], [], "hexpm", "880a0797752da1a4c508ac48f94711e04c86156f498065a83d160eef945858f8"}, diff --git a/test/support/accounts/user.ex b/test/support/accounts/user.ex index b3a28a9..8c7a5e3 100644 --- a/test/support/accounts/user.ex +++ b/test/support/accounts/user.ex @@ -70,17 +70,11 @@ defmodule Example.Accounts.User do end end - oauth2 :auth0 do + auth0 :auth0 do client_id(&get_config/2) redirect_uri(&get_config/2) client_secret(&get_config/2) site(&get_config/2) - - authorize_path("/authorize") - token_path("/oauth/token") - user_path("/userinfo") - authorization_params(scope: "openid profile email") - auth_method(:client_secret_post) end end