Skip to content

Commit

Permalink
Merge pull request #25 from lessless/master
Browse files Browse the repository at this point in the history
Update dependencies and docs
  • Loading branch information
yordis authored Apr 18, 2019
2 parents 9ebecf3 + f009733 commit 128680c
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 73 deletions.
5 changes: 5 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 140
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
[
Expand Down
39 changes: 22 additions & 17 deletions lib/ueberauth/strategy/identity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand All @@ -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
Expand Down
41 changes: 20 additions & 21 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
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
[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
Expand All @@ -26,13 +28,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

Expand All @@ -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
24 changes: 16 additions & 8 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -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"},
}
15 changes: 9 additions & 6 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 25 additions & 18 deletions test/ueberauth/strategy/identity_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand All @@ -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"

Expand Down

0 comments on commit 128680c

Please sign in to comment.