Current section

Files

Jump to
indieweb lib indieweb auth adapters scope.ex
Raw

lib/indieweb/auth/adapters/scope.ex

defmodule IndieWeb.Auth.Adapters.DefaultScopeAdapter do
@moduledoc """
Provides a implementation of the stateful parts of IndieAuth.
"""
@behaviour IndieWeb.Auth.ScopeAdapter
# TODO: Should this default to returning 'read'?
@impl true
def get(code, options) do
IndieWeb.Cache.get(do_make_scope_key(code), options)
end
@impl true
def persist(code, scope, options) do
code_age = IndieWeb.Auth.Code.age(options)
case IndieWeb.Cache.set(do_make_scope_key(code), scope, [expire: code_age], options) do
:ok -> :ok
_ -> {:error, :scope_not_persisted}
end
end
defp do_make_scope_key(code) do
"scope_to_code:#{code}"
end
end