mushu8

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

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:

https://github.com/ueberauth/guardian/blob/ef1b52e831eaaa5589cd54da32aa8ec4e0c57d80/lib/guardian/permissions.ex#L370-L375

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

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.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement