mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 09:32:51 +00:00
32 lines
1007 B
Elixir
32 lines
1007 B
Elixir
defmodule MyApp.Guardian do
|
|
use Guardian, otp_app: :myapp
|
|
use Guardian.Permissions.Bitwise
|
|
|
|
def subject_for_token(resource, _claims) do
|
|
# You can use any value for the subject of your token but
|
|
# it should be useful in retrieving the resource later, see
|
|
# how it being used on `resource_from_claims/1` function.
|
|
# A unique `id` is a good subject, a non-unique email address
|
|
# is a poor subject.
|
|
sub = to_string(resource["id"])
|
|
{:ok, sub}
|
|
end
|
|
|
|
def resource_from_claims(claims) do
|
|
# Here we'll look up our resource from the claims, the subject can be
|
|
# found in the `"sub"` key. In `above subject_for_token/2` we returned
|
|
# the resource id so here we'll rely on that to look it up.
|
|
id = claims["sub"]
|
|
# resource = MyApp.get_resource_by_id(id)
|
|
resource = id
|
|
{:ok, resource}
|
|
end
|
|
|
|
@spec add_permissions(map, map) :: map
|
|
def add_permissions(claims, permissions) do
|
|
claims
|
|
|> encode_permissions_into_claims!(permissions)
|
|
end
|
|
|
|
end
|