mushu8

mushu8

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,

Showing Posts 1 to 2

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…

mushu8

mushu8 OP

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews