Giter Site home page Giter Site logo

Comments (5)

scrogson avatar scrogson commented on April 27, 2024

👍

from ueberauth.

hassox avatar hassox commented on April 27, 2024

The Ueberauth.Strategy has a different role than what this module provides, this module is constructing the route matching.

I've seen quite a few pubs that provide a macro to setup routes. I'll catch up with @scrogson and see what options we can rustle up

from ueberauth.

chrismccord avatar chrismccord commented on April 27, 2024

In either case, the generated module should be one that the user explicitly defines, then they plug that in the router

from ueberauth.

chrismccord avatar chrismccord commented on April 27, 2024

For example, it seems the entire code generation could be a normal UeberAuth plug module, which accepts options from the plug, i.e.:

defmodule UeberAuth do
  def init(opts) do
    opts = Application.get_env(:ueberauth, Ueberauth)
    parts = Enum.map(opts[:providers], fn { name, { strategy, options } } ->
      request_path = Dict.get(options, :request_path, Path.join(["/", base_path, to_string(name)]))
      callback_path = Dict.get(options, :callback_path, Path.join(["/", base_path, to_string(name), "callback"]))
      methods = Dict.get(options, :callback_methods, ["GET"]) |> Enum.map(&(String.upcase(to_string(&1))))

      %{
        strategy_name: name,
        strategy: strategy,
        callback_path: callback_path,
        request_path: request_path,
        callback_methods: methods,
        options: options
      }
  end

  def call(conn, opts), do: run!(conn, opts[:base_path], opts[:callback_path], opts)

  defp run!(%Conn{path_info: [base_path | _]}, base_path, _callback_path, opts) do
    conn
    |> Plug.Conn.put_private(:ueberauth_request_options, opts)
    |> Strategy.run_request(opts[:strategy])
  end

  defp run!(%Plug.Conn{path_info: [cb_path | _]} = conn, _base, cb_path, opts) do
    if conn.method in opts[:callback_methods] do
      conn
      |> Plug.Conn.put_private(:ueberauth_request_options, opts)
      |> Strategy.run_callback(opts[:strategy])
    else
      conn
    end
  end
  defp run!(conn, _), do: conn # if we don't match anything just fall through
end

from ueberauth.

scrogson avatar scrogson commented on April 27, 2024

Thanks for the feedback @chrismccord.

from ueberauth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.