https://github.com/groguelon/permify
An Elixir client for the project Permify.
https://github.com/groguelon/permify
authorization elixir permify
Last synced: about 1 year ago
JSON representation
An Elixir client for the project Permify.
- Host: GitHub
- URL: https://github.com/groguelon/permify
- Owner: GRoguelon
- License: mit
- Created: 2022-10-11T00:33:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-11T01:18:54.000Z (over 3 years ago)
- Last Synced: 2024-03-14T15:12:45.197Z (over 2 years ago)
- Topics: authorization, elixir, permify
- Language: Elixir
- Homepage: https://www.permify.co/
- Size: 17.6 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Permify
Permify is an Elixir client for the project [permify](https://www.permify.co/).
[Documentation](https://hexdocs.pm/permify)
## Installation
```elixir
def deps do
[
{:permify, "~> 0.1.0"}
]
end
```
## Usage
### Create a new client
```elixir
client = Permify.Client.new("http://localhost:3476/v1")
```
### Create a schema
```elixir
schema = """
entity user {}
entity organization {
relation admin @user
relation member @user
action view_files = admin or member
action edit_files = admin
}
"""
{:ok, schema_version} = Permify.Schema.write(client, schema)
```
### Create some relationships
```elixir
relationship = %{
entity: %{id: "1", type: "organization"},
relation: "member",
subject: %{id: "1", type: "user"},
schema_version: schema_version
}
Permify.Relationship.write(client, relationship)
```
### Check permissions
```elixir
{:ok, %{"can" => can}} = Permify.Permission.check?(client, %{
action: "edit_files",
depth: 0,
entity: %{type: "organization", id: "1"},
subject: %{id: "1", type: "user"}
})
IO.inspect(can, label: "Is authorized")
```