Skip to content

Commit

Permalink
update docs in permisson to reflect 2.0.0 (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanspagh authored and doomspork committed Jan 28, 2020
1 parent c9c5307 commit 62744fb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/guardian/permissions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ defmodule Guardian.Permissions do
}
}
use Guardian.Permissions.Bitwise
use Guardian.Permissions, :encoding: Guardian.Permissions.BitwiseEncoding
# Per default permissons will be encoded Bitwise, but other encoders also exist
# * Guardian.Permissions.TextEncoding
# * Guardian.Permissions.AtomEncoing
# It is even posible to supply your own encoding module
# snip
Expand Down Expand Up @@ -78,23 +82,23 @@ defmodule Guardian.Permissions do
### Using with Plug
To use a plug for ensuring permissions you can use the `Guardian.Permissions.BitwiseEncoding` module as part of a
To use a plug for ensuring permissions you can use the `Guardian.Permissions` module as part of a
Guardian pipeline.
```elixir
# After a pipeline has setup the implementation module and error handler
# Ensure that both the `public_profile` and `user_actions.books` permissions are present in the token
plug Guardian.Permissions.BitwiseEncoding. ensure: %{default: [:public_profile], user_actions: [:books]}
plug Guardian.Permissions, ensure: %{default: [:public_profile], user_actions: [:books]}
# Allow the request to continue when the token contains any of the permission sets specified
plug Guardian.Permissions.BitwiseEncoding. one_of: [
plug Guardian.Permissions, one_of: [
%{default: [:public_profile], user_actions: [:books]},
%{default: [:public_profile], user_actions: [:music]},
]
# Look for permissions for a token in a different location
plug Guardian.Permissions.BitwiseEncoding. key: :impersonate, ensure: %{default: [:public_profile]}
plug Guardian.Permissions, key: :impersonate, ensure: %{default: [:public_profile]}
```
If the token satisfies either the permissions listed in `ensure` or one of the sets in the `one_of` key
Expand Down Expand Up @@ -173,7 +177,7 @@ defmodule Guardian.Permissions do

@doc """
Decodes permissions directly from a claims map. This does the same as `decode_permissions` but
will fetch the permissions map from the `"pem"` key where `Guardian.Permissions.BitwiseEncoding. places them
will fetch the permissions map from the `"pem"` key where `Guardian.Permissions places them
when it encodes them into claims.
"""
@spec decode_permissions_from_claims(Guardian.Token.claims()) :: Guardian.Permissions.t()
Expand Down Expand Up @@ -266,7 +270,7 @@ defmodule Guardian.Permissions do
iex> MyTokens.validate_permissions!(%{default: [:user_about_me]})
iex> MyTokens.validate_permissions!(%{not: [:a, :thing]})
raise Guardian.Permissions.BitwiseEncoding.PermissionNotFoundError
raise Guardian.Permissions.PermissionNotFoundError
"""
def validate_permissions!(map) when is_map(map) do
Enum.all?(&do_validate_permissions!/1)
Expand Down

0 comments on commit 62744fb

Please sign in to comment.