-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:tobiasbernet/schlusseli into main
- Loading branch information
Showing
15 changed files
with
477 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
[ | ||
import_deps: [:ecto, :phoenix], | ||
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
subdirectories: ["priv/*/migrations"] | ||
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
defmodule SchlusseliWeb.Resolvers.Customer do | ||
|
||
alias Schlusseli.Factory | ||
|
||
def list_customers(_parent, _args, _resolution) do | ||
def list_customers(_parent, _args, %{context: %{claims: _context}}) do | ||
{:ok, Factory.build_list(10, :customer)} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
defmodule SchlusseliWeb.Resolvers.Key do | ||
|
||
alias Schlusseli.Factory | ||
|
||
def list_keys(_parent, _args, _resolution) do | ||
{:ok, Factory.build_list(10, :key)} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
defmodule SchlusseliWeb.Schema do | ||
use Absinthe.Schema | ||
|
||
import_types SchlusseliWeb.Schema.KeyTypes | ||
import_types SchlusseliWeb.Schema.CustomerTypes | ||
import_types(SchlusseliWeb.Schema.KeyTypes) | ||
import_types(SchlusseliWeb.Schema.CustomerTypes) | ||
|
||
alias SchlusseliWeb.Resolvers | ||
|
||
query do | ||
|
||
@desc "Get all keys" | ||
field :keys, list_of(:key) do | ||
resolve &Resolvers.Key.list_keys/3 | ||
resolve(&Resolvers.Key.list_keys/3) | ||
end | ||
|
||
@desc "Get all customers" | ||
field :customers, list_of(:customer) do | ||
resolve &Resolvers.Customer.list_customers/3 | ||
middleware(SchlusseliWeb.Schema.Middleware.Authorize, "view_customers") | ||
resolve(&Resolvers.Customer.list_customers/3) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule SchlusseliWeb.Schema.Middleware.Authorize do | ||
@behaviour Absinthe.Middleware | ||
|
||
def call(resolution, scope) do | ||
with %{claims: %{scope: current_scopes}} <- resolution.context, | ||
true <- correct_scope?(current_scopes, scope) do | ||
resolution | ||
else | ||
_ -> | ||
resolution | ||
|> Absinthe.Resolution.put_result({:error, "unauthorized"}) | ||
end | ||
end | ||
|
||
defp correct_scope?(current_scopes, scope), do: String.contains?(current_scopes, scope) | ||
end |
Oops, something went wrong.