Packages
boruta
0.1.0-rc.3
3.0.0-beta.4
3.0.0-beta.3
3.0.0-beta.2
3.0.0-beta.1
2.3.6
2.3.5
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.2
2.2.1
2.2.0
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.2.1
0.2.0
0.1.1
0.1.0
0.1.0-rc.5
0.1.0-rc.4
0.1.0-rc.3
0.1.0-rc.2
0.1.0-rc.1
Core of an OAuth/OpenID Connect provider enabling authorization in your applications.
Current section
44 Versions
Jump to
Current section
44 Versions
Compare versions
12
files changed
+95
additions
-73
deletions
| @@ -8,6 +8,7 @@ | |
| 8 8 | <<"lib/ex_json_schema/validator/error">>, |
| 9 9 | <<"lib/ex_json_schema/validator/error/boruta_formatter.ex">>, |
| 10 10 | <<"lib/boruta.ex">>,<<"lib/mix">>,<<"lib/mix/tasks">>, |
| 11 | + <<"lib/mix/tasks/.boruta.gen.migrations.ex.swp">>, |
| 11 12 | <<"lib/mix/tasks/boruta.gen.migrations.ex">>,<<"lib/boruta">>, |
| 12 13 | <<"lib/boruta/pow">>,<<"lib/boruta/pow/user.ex">>, |
| 13 14 | <<"lib/boruta/pow/hash_salt.ex">>,<<"lib/boruta/admin">>, |
| @@ -37,6 +38,7 @@ | |
| 37 38 | <<"lib/boruta/utils/token_generator.ex">>,<<"priv">>,<<"priv/repo">>, |
| 38 39 | <<"priv/repo/migrations">>, |
| 39 40 | <<"priv/repo/migrations/20190728132116_create_boruta.exs">>, |
| 41 | + <<"priv/repo/migrations/20190827130536_users_scopes_association.exs">>, |
| 40 42 | <<"priv/repo/seeds.exs">>,<<".formatter.exs">>,<<"mix.exs">>, |
| 41 43 | <<"README.md">>,<<"LICENSE">>]}. |
| 42 44 | {<<"licenses">>,[<<"MIT">>]}. |
| @@ -78,4 +80,4 @@ | |
| 78 80 | {<<"optional">>,false}, |
| 79 81 | {<<"repository">>,<<"hexpm">>}, |
| 80 82 | {<<"requirement">>,<<"~> 1.0.11">>}]]}. |
| 81 | - {<<"version">>,<<"0.1.0-rc.2">>}. |
| 83 | + {<<"version">>,<<"0.1.0-rc.3">>}. |
| @@ -18,8 +18,9 @@ defmodule Boruta.Admin.Clients do | |
| 18 18 | |
| 19 19 | """ |
| 20 20 | def list_clients do |
| 21 | - repo().all(Client) |
| 22 | - |> repo().preload(:authorized_scopes) |
| 21 | + clients = repo().all(Client) |
| 22 | + |
| 23 | + repo().preload(clients, :authorized_scopes) |
| 23 24 | end |
| 24 25 | |
| 25 26 | @doc """ |
| @@ -37,8 +38,9 @@ defmodule Boruta.Admin.Clients do | |
| 37 38 | |
| 38 39 | """ |
| 39 40 | def get_client!(id) do |
| 40 | - repo().get!(Client, id) |
| 41 | - |> repo().preload(:authorized_scopes) |
| 41 | + client = repo().get!(Client, id) |
| 42 | + |
| 43 | + repo().preload(client, :authorized_scopes) |
| 42 44 | end |
| 43 45 | |
| 44 46 | @doc """ |
| @@ -6,11 +6,9 @@ defmodule Boruta.Oauth do | |
| 6 6 | """ |
| 7 7 | |
| 8 8 | alias Boruta.Oauth.Authorization |
| 9 | - alias Boruta.Oauth.CodeRequest |
| 10 9 | alias Boruta.Oauth.Error |
| 11 10 | alias Boruta.Oauth.Introspect |
| 12 11 | alias Boruta.Oauth.Request |
| 13 | - alias Boruta.Oauth.TokenRequest |
| 14 12 | |
| 15 13 | @doc """ |
| 16 14 | Triggers `token_success` in case of success and `token_error` in case of failure from the given `module`. Those functions are described in `Boruta.Oauth.Application` behaviour. |
| @@ -38,9 +36,9 @@ defmodule Boruta.Oauth do | |
| 38 36 | module.authorize_success(conn, token) |
| 39 37 | else |
| 40 38 | {:error, %Error{} = error} -> |
| 41 | - with {:ok, request} <- Request.authorize_request(conn) do |
| 42 | - module.authorize_error(conn, error_with_format(request, error)) |
| 43 | - else |
| 39 | + case Request.authorize_request(conn) do |
| 40 | + {:ok, request} -> |
| 41 | + module.authorize_error(conn, Error.with_format(error, request)) |
| 44 42 | _ -> |
| 45 43 | module.authorize_error(conn, error) |
| 46 44 | end |
| @@ -60,13 +58,4 @@ defmodule Boruta.Oauth do | |
| 60 58 | module.introspect_error(conn, error) |
| 61 59 | end |
| 62 60 | end |
| 63 | - |
| 64 | - # private |
| 65 | - defp error_with_format(%CodeRequest{redirect_uri: redirect_uri}, %Error{} = error) do |
| 66 | - %{error | format: :query, redirect_uri: redirect_uri} |
| 67 | - end |
| 68 | - defp error_with_format(%TokenRequest{redirect_uri: redirect_uri}, %Error{} = error) do |
| 69 | - %{error | format: :fragment, redirect_uri: redirect_uri} |
| 70 | - end |
| 71 | - defp error_with_format(_, error), do: error |
| 72 61 | end |
| @@ -8,27 +8,27 @@ defmodule Boruta.Oauth.Application do | |
| 8 8 | @doc """ |
| 9 9 | This function will be triggered in case of success triggering `Boruta.Oauth.token/2` |
| 10 10 | """ |
| 11 | - @callback token_success(conn :: Plug.Conn.t(), token :: Boruta.Oauth.Token.t()) :: Plug.Conn.t() |
| 11 | + @callback token_success(conn :: Plug.Conn.t(), token :: Boruta.Oauth.Token.t()) :: any() |
| 12 12 | @doc """ |
| 13 13 | This function will be triggered in case of failure triggering `Boruta.Oauth.token/2` |
| 14 14 | """ |
| 15 | - @callback token_error(conn :: Plug.Conn.t(), oauth_error :: Boruta.Oauth.Error.t()) :: Plug.Conn.t() |
| 15 | + @callback token_error(conn :: Plug.Conn.t(), oauth_error :: Boruta.Oauth.Error.t()) :: any() |
| 16 16 | |
| 17 17 | @doc """ |
| 18 18 | This function will be triggered in case of success triggering `Boruta.Oauth.authorize/2` |
| 19 19 | """ |
| 20 | - @callback authorize_success(conn :: Plug.Conn.t(), token :: Boruta.Oauth.Token.t()) :: Plug.Conn.t() |
| 20 | + @callback authorize_success(conn :: Plug.Conn.t(), token :: Boruta.Oauth.Token.t()) :: any() |
| 21 21 | @doc """ |
| 22 22 | This function will be triggered in case of failure triggering `Boruta.Oauth.authorize/2` |
| 23 23 | """ |
| 24 | - @callback authorize_error(conn :: Plug.Conn.t(), oauth_error :: Boruta.Oauth.Error.t()) :: Plug.Conn.t() |
| 24 | + @callback authorize_error(conn :: Plug.Conn.t(), oauth_error :: Boruta.Oauth.Error.t()) :: any() |
| 25 25 | |
| 26 26 | @doc """ |
| 27 27 | This function will be triggered in case of success triggering `Boruta.Oauth.introspect/2` |
| 28 28 | """ |
| 29 | - @callback introspect_success(conn :: Plug.Conn.t(), token :: Boruta.Oauth.Token.t()) :: Plug.Conn.t() |
| 29 | + @callback introspect_success(conn :: Plug.Conn.t(), token :: Boruta.Oauth.Token.t()) :: any() |
| 30 30 | @doc """ |
| 31 31 | This function will be triggered in case of failure triggering `Boruta.Oauth.introspect/2` |
| 32 32 | """ |
| 33 | - @callback introspect_error(conn :: Plug.Conn.t(), oauth_error :: Boruta.Oauth.Error.t()) :: Plug.Conn.t() |
| 33 | + @callback introspect_error(conn :: Plug.Conn.t(), oauth_error :: Boruta.Oauth.Error.t()) :: any() |
| 34 34 | end |
| @@ -29,17 +29,17 @@ defmodule Boruta.Oauth.Authorization.Base do | |
| 29 29 | :status => :unauthorized |
| 30 30 | }} |
| 31 31 | def client(id: id, secret: secret) do |
| 32 | - with %Client{} = client <- repo().get_by(Client, id: id, secret: secret) do |
| 33 | - {:ok, client} |
| 34 | - else |
| 32 | + case repo().get_by(Client, id: id, secret: secret) do |
| 33 | + %Client{} = client -> |
| 34 | + {:ok, client} |
| 35 35 | nil -> |
| 36 36 | {:error, %Error{status: :unauthorized, error: :invalid_client, error_description: "Invalid client_id or client_secret."}} |
| 37 37 | end |
| 38 38 | end |
| 39 39 | def client(id: id, redirect_uri: redirect_uri) do |
| 40 | - with %Client{} = client <- repo().get_by(Client, id: id, redirect_uri: redirect_uri) do |
| 41 | - {:ok, client} |
| 42 | - else |
| 40 | + case repo().get_by(Client, id: id, redirect_uri: redirect_uri) do |
| 41 | + %Client{} = client -> |
| 42 | + {:ok, client} |
| 43 43 | nil -> |
| 44 44 | {:error, %Error{status: :unauthorized, error: :invalid_client, error_description: "Invalid client_id or redirect_uri."}} |
| 45 45 | end |
| @@ -64,9 +64,9 @@ defmodule Boruta.Oauth.Authorization.Base do | |
| 64 64 | | {:ok, user :: struct()} |
| 65 65 | def resource_owner(id: id) do |
| 66 66 | # if resource_owner is a struct |
| 67 | - with %{__struct__: _} = resource_owner <- repo().get_by(resource_owner_schema(), id: id) do |
| 68 | - {:ok, resource_owner} |
| 69 | - else |
| 67 | + case repo().get_by(resource_owner_schema(), id: id) do |
| 68 | + %{__struct__: _} = resource_owner -> |
| 69 | + {:ok, resource_owner} |
| 70 70 | _ -> |
| 71 71 | {:error, %Error{ |
| 72 72 | status: :unauthorized, |
Loading more files…