Skip to content

Split adding URL to private into separate module #1

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

Open
byjpr opened this issue Jul 23, 2021 · 0 comments
Open

Split adding URL to private into separate module #1

byjpr opened this issue Jul 23, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@byjpr
Copy link
Owner

byjpr commented Jul 23, 2021

In Enron I have a module (EnronWeb.Plug.ResourceFromJWT) which takes the URL from JWT Claims and puts it into a private key of it's own. It may make more sense to split it out in the public version of this plug too.

defmodule EnronWeb.Plug.ResourceFromJWT do
  @moduledoc """
  Loads Shop from JWT
  """
  import Plug.Conn

  @doc false
  def init(opts), do: opts

  @doc false
  def call(%{private: %{shop_origin_type: :jwt}} = conn, _config) do
    conn
    |> put_private(:enron_shop_name, jwt_shopify_url(conn))
  end

  def call(conn, _config), do: conn

  defp jwt_shopify_url(conn),
    do: conn.private[:shopify_jwt_claims] |> Map.fetch!("dest") |> String.replace("https://", "")
end
@byjpr byjpr added the enhancement New feature or request label Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant