From 932577d563978555bc9c6f5b14f852aacf35ff04 Mon Sep 17 00:00:00 2001 From: lessless Date: Wed, 17 Apr 2019 21:34:45 +0200 Subject: [PATCH 1/4] Update dependencies --- mix.exs | 10 +++++----- mix.lock | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/mix.exs b/mix.exs index d9ab7f4..fdfd2b7 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule UeberauthIdentity.Mixfile do use Mix.Project - @version "0.2.3" + @version "0.2.4" @url "https://github.com/ueberauth/ueberauth_identity" def project do @@ -26,13 +26,13 @@ defmodule UeberauthIdentity.Mixfile do defp deps do [ {:plug, "~> 1.0"}, - {:ueberauth, "~> 0.2"}, + {:ueberauth, "~> 0.6"}, # dev/test dependencies - {:credo, "~> 0.5", only: [:dev, :test]}, + {:credo, "~> 1.0", only: [:dev, :test]}, {:dogma, ">= 0.0.0", only: [:dev, :test]}, - {:earmark, "~> 0.1", only: :dev}, - {:ex_doc, "~> 0.1", only: :dev}, + {:earmark, "~> 1.0", only: :dev}, + {:ex_doc, "~> 0.20", only: :dev}, ] end diff --git a/mix.lock b/mix.lock index d71f651..3f774cc 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,16 @@ -%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []}, - "credo": {:hex, :credo, "0.5.3", "0c405b36e7651245a8ed63c09e2d52c2e2b89b6d02b1570c4d611e0fcbecf4a2", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]}, - "dogma": {:hex, :dogma, "0.0.11", "1396bfe10a962b5c5b0468eba6eb3be85d693d55f2d698fda29660a059eb2180", [:mix], [{:poison, "~> 1.0", [hex: :poison, optional: false]}]}, - "earmark": {:hex, :earmark, "0.1.19", "ffec54f520a11b711532c23d8a52b75a74c09697062d10613fa2dbdf8a9db36e", [:mix], []}, - "ex_doc": {:hex, :ex_doc, "0.10.0", "f49c237250b829df986486b38f043e6f8e19d19b41101987f7214543f75947ec", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]}, - "plug": {:hex, :plug, "1.0.3", "8bbcbdaa4cb15170b9a15cb12153e8a6d9e176ce78e4c1990ea0b505b0ca24a0", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}]}, - "poison": {:hex, :poison, "1.5.2", "560bdfb7449e3ddd23a096929fb9fc2122f709bcc758b2d5d5a5c7d0ea848910", [:mix], []}, - "ueberauth": {:hex, :ueberauth, "0.2.0", "9160c601b468c6692462a56be7ad8890d1a2d84519d7d9c4541da5b07d6495e1", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]}} +%{ + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, + "credo": {:hex, :credo, "1.0.4", "d2214d4cc88c07f54004ffd5a2a27408208841be5eca9f5a72ce9e8e835f7ede", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, + "dogma": {:hex, :dogma, "0.1.16", "3c1532e2f63ece4813fe900a16704b8e33264da35fdb0d8a1d05090a3022eef9", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, + "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, + "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, + "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, + "plug": {:hex, :plug, "1.8.0", "9d2685cb007fe5e28ed9ac27af2815bc262b7817a00929ac10f56f169f43b977", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"}, + "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"}, + "poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"}, + "ueberauth": {:hex, :ueberauth, "0.6.1", "9e90d3337dddf38b1ca2753aca9b1e53d8a52b890191cdc55240247c89230412", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, +} From 91f6d9e46985b75738788d6ead357f778f0e1616 Mon Sep 17 00:00:00 2001 From: lessless Date: Wed, 17 Apr 2019 21:37:23 +0200 Subject: [PATCH 2/4] Format files --- config/config.exs | 2 +- config/test.exs | 2 +- lib/ueberauth/strategy/identity.ex | 39 +++++++++++--------- mix.exs | 33 +++++++++-------- test/test_helper.exs | 15 ++++---- test/ueberauth/strategy/identity_test.exs | 43 +++++++++++++---------- 6 files changed, 74 insertions(+), 60 deletions(-) diff --git a/config/config.exs b/config/config.exs index 507712c..c4f33d2 100644 --- a/config/config.exs +++ b/config/config.exs @@ -28,7 +28,7 @@ use Mix.Config # here (which is why it is important to import them last). # # import_config "#{Mix.env}.exs" -if Mix.env == :test, do: import_config "test.exs" +if Mix.env() == :test, do: import_config("test.exs") config :dogma, rule_set: Dogma.RuleSet.All diff --git a/config/test.exs b/config/test.exs index fe74b3d..34112b3 100644 --- a/config/test.exs +++ b/config/test.exs @@ -2,7 +2,7 @@ use Mix.Config config :ueberauth, Ueberauth, providers: [ - identity: { Ueberauth.Strategy.Identity, [] }, + identity: {Ueberauth.Strategy.Identity, []}, identity_with_options: { Ueberauth.Strategy.Identity, [ diff --git a/lib/ueberauth/strategy/identity.ex b/lib/ueberauth/strategy/identity.ex index c6ead4c..25f2bf7 100644 --- a/lib/ueberauth/strategy/identity.ex +++ b/lib/ueberauth/strategy/identity.ex @@ -3,19 +3,20 @@ defmodule Ueberauth.Strategy.Identity do A username/password strategy for Ueberauth """ - use Ueberauth.Strategy, uid_field: :email, - email_field: :email, - name_field: :name, - first_name_field: :first_name, - last_name_field: :last_name, - nickname_field: :nickname, - phone_field: :phone, - location_field: :location, - description_field: :description, - password_field: :password, - password_confirmation_field: :password_confirmation, - param_nesting: nil, - scrub_params: true + use Ueberauth.Strategy, + uid_field: :email, + email_field: :email, + name_field: :name, + first_name_field: :first_name, + last_name_field: :last_name, + nickname_field: :nickname, + phone_field: :phone, + location_field: :location, + description_field: :description, + password_field: :password, + password_confirmation_field: :password_confirmation, + param_nesting: nil, + scrub_params: true alias Ueberauth.Auth.Info alias Ueberauth.Auth.Credentials @@ -68,12 +69,15 @@ defmodule Ueberauth.Strategy.Identity do end defp param_for(conn, name, nesting) do - attrs = nesting - |> List.wrap - |> Enum.map(fn(item) -> to_string(item) end) + attrs = + nesting + |> List.wrap() + |> Enum.map(fn item -> to_string(item) end) case Kernel.get_in(conn.params, attrs) do - nil -> nil + nil -> + nil + nested -> nested |> Map.get(to_string(option(conn, name))) @@ -82,6 +86,7 @@ defmodule Ueberauth.Strategy.Identity do end defp scrub_param(param, false), do: param + defp scrub_param(param, _) do if scrub?(param), do: nil, else: param end diff --git a/mix.exs b/mix.exs index fdfd2b7..8afea38 100644 --- a/mix.exs +++ b/mix.exs @@ -5,18 +5,20 @@ defmodule UeberauthIdentity.Mixfile do @url "https://github.com/ueberauth/ueberauth_identity" def project do - [app: :ueberauth_identity, - version: @version, - name: "Ueberauth Identity", - package: package(), - elixir: "~> 1.2", - build_embedded: Mix.env == :prod, - start_permanent: Mix.env == :prod, - source_url: @url, - homepage_url: @url, - description: description(), - deps: deps(), - docs: docs()] + [ + app: :ueberauth_identity, + version: @version, + name: "Ueberauth Identity", + package: package(), + elixir: "~> 1.2", + build_embedded: Mix.env() == :prod, + start_permanent: Mix.env() == :prod, + source_url: @url, + homepage_url: @url, + description: description(), + deps: deps(), + docs: docs() + ] end def application do @@ -32,7 +34,7 @@ defmodule UeberauthIdentity.Mixfile do {:credo, "~> 1.0", only: [:dev, :test]}, {:dogma, ">= 0.0.0", only: [:dev, :test]}, {:earmark, "~> 1.0", only: :dev}, - {:ex_doc, "~> 0.20", only: :dev}, + {:ex_doc, "~> 0.20", only: :dev} ] end @@ -49,9 +51,6 @@ defmodule UeberauthIdentity.Mixfile do end defp package do - [files: ["lib", "mix.exs", "README.md", "LICENSE"], - maintainers: ["Daniel Neighman"], - licenses: ["MIT"], - links: %{github: @url}] + [files: ["lib", "mix.exs", "README.md", "LICENSE"], maintainers: ["Daniel Neighman"], licenses: ["MIT"], links: %{github: @url}] end end diff --git a/test/test_helper.exs b/test/test_helper.exs index a7d6563..8f9901a 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -2,22 +2,25 @@ defmodule SpecRouter do require Ueberauth use Plug.Router - plug :fetch_query_params + plug(:fetch_query_params) - plug Ueberauth, base_path: "/auth" + plug(Ueberauth, base_path: "/auth") - plug :match - plug :dispatch + plug(:match) + plug(:dispatch) + + get("/auth/identity", do: send_resp(conn, 200, "identity request")) - get "/auth/identity", do: send_resp(conn, 200, "identity request") get "/auth/identity_with_options" do send_resp(conn, 200, "identity with options request") end - get "/auth/identity/callback", do: send_resp(conn, 200, "identity callback") + get("/auth/identity/callback", do: send_resp(conn, 200, "identity callback")) + get "/auth/identity_with_options/callback" do send_resp(conn, 200, "identity with options callback") end + get "/auth/identity_with_nested_options/callback" do send_resp(conn, 200, "identity with nested options callback") end diff --git a/test/ueberauth/strategy/identity_test.exs b/test/ueberauth/strategy/identity_test.exs index 475b8f7..7e015d8 100644 --- a/test/ueberauth/strategy/identity_test.exs +++ b/test/ueberauth/strategy/identity_test.exs @@ -6,9 +6,10 @@ defmodule Ueberauth.Strategy.IdentityTest do @router SpecRouter.init([]) test "request phase" do - conn = :get - |> conn("/auth/identity") - |> SpecRouter.call(@router) + conn = + :get + |> conn("/auth/identity") + |> SpecRouter.call(@router) assert conn.resp_body == "identity request" end @@ -29,9 +30,10 @@ defmodule Ueberauth.Strategy.IdentityTest do query = URI.encode_query(opts) - conn = :get - |> conn("/auth/identity/callback?#{query}") - |> SpecRouter.call(@router) + conn = + :get + |> conn("/auth/identity/callback?#{query}") + |> SpecRouter.call(@router) assert conn.resp_body == "identity callback" @@ -74,17 +76,19 @@ defmodule Ueberauth.Strategy.IdentityTest do "user[first_name]" => "Fred", "user[last_name]" => "Flintstone", "user[username]" => "freddy", - "user[phone]" => "555-555-5555", + "user[phone]" => "555-555-5555", "user[description]" => "Cave man", "user[location]" => "Bedrock", "user[password]" => "sekrit", "user[password_confirmation]" => "sekrit" } + query = URI.encode_query(opts) - conn = :get - |> conn("/auth/identity_with_options/callback?#{query}") - |> SpecRouter.call(@router) + conn = + :get + |> conn("/auth/identity_with_options/callback?#{query}") + |> SpecRouter.call(@router) assert conn.resp_body == "identity with options callback" @@ -112,17 +116,19 @@ defmodule Ueberauth.Strategy.IdentityTest do "data[attributes][first_name]" => "Fred", "data[attributes][last_name]" => "Flintstone", "data[attributes][username]" => "freddy", - "data[attributes][phone]" => "555-555-5555", + "data[attributes][phone]" => "555-555-5555", "data[attributes][description]" => "Cave man", "data[attributes][location]" => "Bedrock", "data[attributes][password]" => "sekrit", "data[attributes][password_confirmation]" => "sekrit" } + query = URI.encode_query(opts) - conn = :get - |> conn("/auth/identity_with_nested_options/callback?#{query}") - |> SpecRouter.call(@router) + conn = + :get + |> conn("/auth/identity_with_nested_options/callback?#{query}") + |> SpecRouter.call(@router) assert conn.resp_body == "identity with nested options callback" @@ -146,14 +152,15 @@ defmodule Ueberauth.Strategy.IdentityTest do test "scrub params" do opts = %{ email: "foo@example.com", - name: "", + name: "" } query = URI.encode_query(opts) - conn = :get - |> conn("/auth/identity/callback?#{query}") - |> SpecRouter.call(@router) + conn = + :get + |> conn("/auth/identity/callback?#{query}") + |> SpecRouter.call(@router) assert conn.resp_body == "identity callback" From 092ae1518e06abe01b96edcd325b9df2acbf76df Mon Sep 17 00:00:00 2001 From: lessless Date: Wed, 17 Apr 2019 21:38:01 +0200 Subject: [PATCH 3/4] Add formatter settings --- .formatter.exs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .formatter.exs diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..0cf93db --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,5 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], + line_length: 140 +] From f00973350ec93f16ad80c575fe10f464f64442de Mon Sep 17 00:00:00 2001 From: lessless Date: Wed, 17 Apr 2019 21:43:04 +0200 Subject: [PATCH 4/4] Fix documentation as per #23 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bbe6d6..7102a27 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ If you want to disable that behaviour set the following option in your config: Depending on the configured url you can initial the request through: - /auth/identity + /auth/identity/callback ## License