Ueberauth raises: function MyAppWeb.OAuthController.request/2 is undefined or private

Ueberauth raises the error below but I don’t see what is wrong with my code.

function MyAppWeb.OAuthController.request/2 is undefined or private

As far as I understand the request/2 controller action doesn’t need to be implemented as the ueberauth_google lib will redirect to Google sign on.

mix.exs:

defp deps do
  [
    {:ueberauth, "~> 0.10"},
    {:ueberauth_google, "~> 0.10"},
    # ...
  ]
end

config.exs:

config :ueberauth, Ueberauth.Strategy.Google.OAuth,
  client_id: "xxx",
  client_secret: "xxx"

config :ueberauth, Ueberauth,
  providers: [
    google: {Ueberauth.Strategy.Google, []}
  ]

router.ex:

scope "/" do
  pipe_through :api

  get "/:provider", MyAppWeb.OAuthController, :request
  get "/:provider/callback", MyAppWeb.OAuthController, :callback
end

oauth_controller.ex:

defmodule MyAppWeb.OAuthController do
  use MyAppWeb, :controller

  plug Ueberauth

  def callback(%{assigns: %{ueberauth_auth: ueberauth_data}} = conn, _params) do
    # ...
  end

  def callback(%{assigns: %{ueberauth_failure: _}} = conn, _params) do
    # ...
  end
end

Execute:

GET http://localhost:4000/google

Result

UndefinedFunctionError at GET /google

function MyAppWeb.OAuthController.request/2 is undefined or private

I finally found the error, I had to configure the :base_path option according to my routes. By default, the :base_path is assumed to be /auth.

I think this option should be forced to be explicitly set.

1 Like