mirror of
https://github.com/team-alembic/ash_authentication_phoenix.git
synced 2024-09-19 21:13:52 +12:00
improvement: Add Github icon. (#55)
This commit is contained in:
parent
1b5c216856
commit
dbc9fcc5a8
6 changed files with 41 additions and 4 deletions
|
@ -34,6 +34,11 @@ config :ash_authentication_phoenix, Example.Accounts.User,
|
|||
client_secret: System.get_env("OAUTH2_CLIENT_SECRET"),
|
||||
redirect_uri: "http://localhost:4000/auth",
|
||||
site: System.get_env("OAUTH2_SITE")
|
||||
],
|
||||
github: [
|
||||
client_id: System.get_env("GITHUB_CLIENT_ID"),
|
||||
client_secret: System.get_env("GITHUB_CLIENT_SECRET"),
|
||||
redirect_uri: "http://localhost:4000/auth"
|
||||
]
|
||||
]
|
||||
]
|
||||
|
|
|
@ -8,6 +8,8 @@ defmodule DevWeb.HomePageLive do
|
|||
@impl true
|
||||
@spec render(Socket.assigns()) :: Rendered.t() | no_return
|
||||
def render(assigns) do
|
||||
assigns = assign_new(assigns, :current_user, fn -> nil end)
|
||||
|
||||
~H"""
|
||||
<%= if @current_user do %>
|
||||
<h2>Current user: <%= @current_user.email %></h2>
|
||||
|
|
|
@ -83,6 +83,14 @@ defmodule AshAuthentication.Phoenix.Components.OAuth2 do
|
|||
</svg>
|
||||
"""
|
||||
|
||||
defp icon_svg(:github, class),
|
||||
do: ~s"""
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="#{class}">
|
||||
<path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22">
|
||||
</path>
|
||||
</svg>
|
||||
"""
|
||||
|
||||
defp strategy_name(strategy) do
|
||||
case strategy.name do
|
||||
:oauth2 -> "OAuth"
|
||||
|
|
2
mix.exs
2
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.3"},
|
||||
{:ash_authentication, "~> 3.5"},
|
||||
{:ash_phoenix, "~> 1.1"},
|
||||
{:ash, "~> 2.2"},
|
||||
{:jason, "~> 1.0"},
|
||||
|
|
2
mix.lock
2
mix.lock
|
@ -1,6 +1,6 @@
|
|||
%{
|
||||
"ash": {:hex, :ash, "2.5.1", "ea0716f8409c09d62dfa95cafbe2e95aedd126e315cbf4a8febb5ccf88050fef", [: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 and >= 0.3.2", [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", "c717b284bbdad2ff7c8e0e04efbc3c6b1b2af915f97ed56e008f7e8a5f60acee"},
|
||||
"ash_authentication": {:hex, :ash_authentication, "3.3.1", "58831de82880b9c4e822621b2d61b5c6189ec88381b1785c569a1f144db9a352", [: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.4", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "77cd385f2e1ff7652d6639a72f6d3aed69a374c4dd1ca5a1d3835280cdb07240"},
|
||||
"ash_authentication": {:hex, :ash_authentication, "3.5.1", "6de36971550016b1e1f3190391783a3b39925870cbdcde60b8301bae86f5fca6", [: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.4", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "c20eed2864045e5f0c071467d84f1781d1fd3511a6f4604fd68d99e4d5e52475"},
|
||||
"ash_phoenix": {:hex, :ash_phoenix, "1.2.3", "eb2e070f18cb3547650c5df2a93ded2c207ec55d9cdf16e632046a8a802c638b", [:mix], [{:ash, "~> 2.4 and >= 2.4.26", [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", "2d5d760890cd94cb17be9627b6e01c32d9114842b7cdd4aa8f16a0a1b023f995"},
|
||||
"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"},
|
||||
|
|
|
@ -32,6 +32,22 @@ defmodule Example.Accounts.User do
|
|||
|> Ash.Changeset.change_attribute(:email, user_info["email"])
|
||||
end
|
||||
end
|
||||
|
||||
create :register_with_github do
|
||||
argument :user_info, :map, allow_nil?: false
|
||||
argument :oauth_tokens, :map, allow_nil?: false
|
||||
upsert? true
|
||||
upsert_identity :unique_email
|
||||
|
||||
change AshAuthentication.GenerateTokenChange
|
||||
|
||||
change fn changeset, _ ->
|
||||
user_info = Ash.Changeset.get_argument(changeset, :user_info)
|
||||
|
||||
changeset
|
||||
|> Ash.Changeset.change_attribute(:email, user_info["email"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
|
@ -59,7 +75,7 @@ defmodule Example.Accounts.User do
|
|||
end
|
||||
|
||||
strategies do
|
||||
password :password do
|
||||
password do
|
||||
identity_field(:email)
|
||||
hashed_password_field(:hashed_password)
|
||||
|
||||
|
@ -70,12 +86,18 @@ defmodule Example.Accounts.User do
|
|||
end
|
||||
end
|
||||
|
||||
auth0 :auth0 do
|
||||
auth0 do
|
||||
client_id(&get_config/2)
|
||||
redirect_uri(&get_config/2)
|
||||
client_secret(&get_config/2)
|
||||
site(&get_config/2)
|
||||
end
|
||||
|
||||
github do
|
||||
client_id &get_config/2
|
||||
redirect_uri &get_config/2
|
||||
client_secret &get_config/2
|
||||
end
|
||||
end
|
||||
|
||||
tokens do
|
||||
|
|
Loading…
Reference in a new issue