ueberauth / guardian

Elixir Authentication
MIT License
3.43k stars 382 forks source link

module Guardian.Plug is not loaded and could not be found #581

Closed shahryarjb closed 5 years ago

shahryarjb commented 5 years ago

Hello, I have updated my project to new Guardian, but I have a lib/auth_service/guardian.ex:2: module Guardian.Plug is not loaded and could not be found error, it can't be able to load Guardian,

my file:

defmodule AuthService.Guardian do
  use Guardian, otp_app: :auth_service

  def subject_for_token(resource, _claims) do
    # You can use any value for the subject of your token but
    # it should be useful in retrieving the resource later, see
    # how it being used on `resource_from_claims/1` function.
    # A unique `id` is a good subject, a non-unique email address
    # is a poor subject.
    sub = to_string(resource.id)
    {:ok, sub}
  end

  def subject_for_token(_, _) do
    {:error, :reason_for_error}
  end

  def resource_from_claims(claims) do
    # Here we'll look up our resource from the claims, the subject can be
    # found in the `"sub"` key. In `above subject_for_token/2` we returned
    # the resource id so here we'll rely on that to look it up.
    id = claims["sub"]
    resource = AuthService.get_resource_by_id(id)
    {:ok,  resource}
  end

  def resource_from_claims(_claims) do
    {:error, :reason_for_error}
  end
end

I tested mix deps.get && mix deps.compile before this error, but it was not fixed.

my project is umbrella, elixir v1.8.0 and {:guardian, "~> 1.2"}

my config:

config :auth_service, AuthService.Guardian,
  issuer: "auth_service",
  allowed_algos: ["ES512"],
  secret_key: %{
    "alg" => "ES512",
    "crv" => "P-521",
    "d" => "D",
    "kty" => "EC",
    "use" => "sig",
    "x" => "X",
    "y" => "Y"
  }

How can I fix this ?

Thanks

yordis commented 5 years ago

Do you have plug and guardian in your dependencies?

shahryarjb commented 5 years ago

@yordis it's my elixir project under umbrella

  defp deps do
    [
      {:ecto, "3.0.7"}, #1
      {:ecto_sql, "~> 3.0"}, #2
      {:postgrex, ">= 0.0.0"}, #3
      {:comeonin, "~> 5.0"}, #4
      {:bcrypt_elixir, "~> 2.0"}, #5
      {:scrivener_ecto, "~> 2.0"}, #6
      {:guardian, "~> 1.2"}, #7
      {:httpoison, "~> 1.5"}, #8
      {:jose, "~> 1.9"}, #9
      {:plug, "~> 1.7"}
    ]

Have I mistaken anything?

yordis commented 5 years ago

Could you post the stack trace of the error, I can't see anything wrong

shahryarjb commented 5 years ago

@yordis I didn't understand what you told me, sorry, but you need the error?

see the pic plz screenshot 2019-03-01 at 10 15 56 pm

yordis commented 5 years ago

At this point, are you sure you added the dependency to the correct package?

I am not sure what is the issue other than having issues with the dependencies.

shahryarjb commented 5 years ago

It's umbrella project issue again, I delete my build and delete all of sup project deps and this was fixed. after 8 hours :(

Thank you @yordis

yordis commented 5 years ago

@shahryarjb your dependencies can't be under the umbrella but the individual packages under the umbrella, which may be what you called an issue since it is not well documented (people keep making the same mistakes)

I am happy that you figured it out

mithereal commented 5 years ago

this issue has reoccurred again, it is related to docker in my case, as i can compile and everything works fine if i dont use docker