mushu8
Guardian Authorization & Dializer
Hi,
I followed some tutorials and read Hex documentation on Guardian authorization but i get a warning on a basic implementation :
The @spec for the function does not match the success typing of the function.
Function:
CTAPI.Guardian.available_permissions/0
Success typing:
@spec available_permissions() :: %{:default => [:read_users | :write_users, ...]}
Here is my implementation :
defmodule CTAPI.Guardian do
@moduledoc """
Integration with Guardian
"""
use Guardian, otp_app: :ct_api
use Guardian.Permissions, encoding: Guardian.Permissions.BitwiseEncoding # <- warning on this line
def subject_for_token(%{id: id}, _claims) do
{:ok, to_string(id)}
end
def subject_for_token(_, _) do
{:error, :no_resource_id}
end
def resource_from_claims(%{"sub" => sub}) do
{:ok, CTAPI.Account.get_user!(sub)}
end
def resource_from_claims(_claims) do
{:error, :no_claims_sub}
end
def build_claims(claims, _resource, opts) do
claims =
claims
|> encode_permissions_into_claims!(Keyword.get(opts, :permissions))
{:ok, claims}
end
end
Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.10.3 (compiled with Erlang/OTP 22)
Can someone at least tell me if i have to fork and fix Gardian for this version of elixir or if i can fix my code please ?
Best regards,
Marked As Solved
al2o3cr
There’s prior discussion of this on the Guardian issue tracker:
https://github.com/ueberauth/guardian/issues/565
The issue appears to be that the generated available_permissions function declares a return type of Guardian.Permission.t() but the code that sets @available_permissions returns a map with a different shape:
Changing the spec on available_permissions to Guardian.Permission.input_permissions would likely fix the error.
The comments on the issue up top that mention “running Dialyzer on master” are a red herring - this code will only cause Dialyzer errors when it’s used in a module, and Dialyzer doesn’t check exs files like tests…
Last Post!
mushu8
Thank you for your answer.
I was trying to remove an annoying warning and i’ve finally decided to implement authorization without help of Guardian.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









