# `Shopifex.Plug.EnsureScopes`
[🔗](https://github.com/ericdude4/shopifex/blob/main/lib/shopifex/plug/ensure_scopes.ex#L1)

Ensures that the shop currently loaded in the session has all of the scopes
defined under `config :shopifex, scopes: "foo"` (or the `:required_scopes`
plug option).

Both the required and the granted scope lists are normalised with
`Shopifex.Scopes.split/1`: whitespace around scope names is ignored and empty
segments are dropped, so an empty (or `nil`) `:scopes` config requires nothing.

## Behaviour on a scope mismatch

For managed-install apps (the 3.0 default) access scopes are declared in your
`shopify.app.toml` `[access_scopes]` and granted by Shopify at install/update —
redirecting merchants into a legacy OAuth re-authorization is the wrong default.
So a scope mismatch **fails with an actionable error** by default rather than
redirecting.

Choose the behaviour with the `:on_missing_scopes` plug option (or the
`config :shopifex, :ensure_scopes_on_missing` application setting; the plug
option wins):

  * `:raise` (default) — raise `Shopifex.RuntimeError` naming the missing scopes.
    Reconcile scopes through your app config; Shopify re-grants them on the next
    managed install/update.
  * `:redirect` — legacy behaviour: render a page that redirects the shop to the
    Shopify OAuth update flow. Use this only for apps still relying on OAuth.

## Examples

    # default: fail with an actionable message
    plug Shopifex.Plug.EnsureScopes

    # opt back into the legacy OAuth-update redirect
    plug Shopifex.Plug.EnsureScopes, on_missing_scopes: :redirect

# `call`

# `init`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
