Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesnt seem to work on phoenix 1.7 #5

Open
reneweteling opened this issue Jul 6, 2023 · 0 comments
Open

doesnt seem to work on phoenix 1.7 #5

reneweteling opened this issue Jul 6, 2023 · 0 comments

Comments

@reneweteling
Copy link

config.exs

config :phoenix, :format_encoders, json: Casex.CamelCaseEncoder

router.ex

  pipeline :api do
    plug :accepts, ["json"]
    plug Casex.CamelCaseDecoderPlug
    plug CoachCloudWeb.Plugs.APIAuthPlug, otp_app: :coach_cloud
    plug OpenApiSpex.Plug.PutApiSpec, module: CoachCloudWeb.ApiSpec
  end


  scope "/api/v1", CoachCloudWeb.Api.V1, as: :api_v1 do
    pipe_through :api
    get "/auth/:provider/new", AuthorizationController, :new
  end

AuthorizationController

  def new(conn, %{"provider" => provider}) do
    conn
    |> Plug.authorize_url(provider, redirect_uri(conn))
    |> case do
      {:ok, url, conn} ->
        json(conn, %{data: %{url: url, session_params: conn.private[:pow_assent_session_params]}})

      {:error, _error, conn} ->
        conn
        |> put_status(:internal_server_error)
        |> json(%{
          error: %{status: :internal_server_error, message: "An unexpected error occurred"}
        })
    end
  end

output:

{
  "data": {
      "session_params": { # should be sessionParams if i understand correctly)
          "state": "55f939d577bc2bafc66ab9010d747f7cae7737238d374"
      },
      "url": "https://accounts.google.com/o/oauth2/v2/auth?client_id=148671880998-4lrl8g6k6lla4tsiljne9bhmsu921iqr.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fauth%2Fgoogle%2Fcallback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&state=55f939d577bc2bafc66ab9010d747f7cae7737238d374"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant