An open API service indexing awesome lists of open source software.

https://github.com/permify/permify-go

Permify Go Client
https://github.com/permify/permify-go

Last synced: 2 months ago
JSON representation

Permify Go Client

Awesome Lists containing this project

README

        




Permify logo


Permify Golang Client



GitHub package.json version 
Permify Licence 
Permify Discord Channel 

# Installation

```shell
go get buf.build/gen/go/permifyco/permify/protocolbuffers/go/base/v1
go get github.com/Permify/permify-go
```

# How to use

### Import Permify.

```go
import (
permify_payload "buf.build/gen/go/permifyco/permify/protocolbuffers/go/base/v1"
permify_grpc "github.com/Permify/permify-go/grpc"
)
```

### Initialize the new Permify client.

```go
// generate new client
client, err := permify_grpc.NewClient(
permify_grpc.Config{
Endpoint: `localhost:3478`,
},
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
```

### Create a new tenant

```go
ct, err := client.Tenancy.Create(context.Background(), &permify_payload.TenantCreateRequest{
Id: "t1",
Name: "tenant 1",
})
```

### Write Schema

```go
sr, err: = client.Schema.Write(context.Background(), &permify_payload.SchemaWriteRequest {
TenantId: "t1",
Schema: `
entity user {}

entity document {

relation viewer @user
action view = viewer
}`,
})
```

### Write Relationships

```go

rr, err := client.Data.WriteRelationships(context.Background(), & permify_payload.RelationshipWriteRequest {
TenantId: "t1",
Metadata: & permify_payload.RelationshipWriteRequestMetadata {
SchemaVersion: sr.SchemaVersion, // sr --> schema write response
},
Tuples: [] * permify_payload.Tuple {
{
Entity: & permify_payload.Entity {
Type: "document",
Id: "1",
},
Relation: "viewer",
Subject: & permify_payload.Subject {
Type: "user",
Id: "1",
},
}, {
Entity: & permify_payload.Entity {
Type: "document",
Id: "3",
},
Relation: "viewer",
Subject: & permify_payload.Subject {
Type: "user",
Id: "1",
},
}
},
})
```

### Check

```go
cr, err := client.Permission.Check(context.Background(), & permify_payload.PermissionCheckRequest {
TenantId: "t1",
Metadata: & permify_payload.PermissionCheckRequestMetadata {
SnapToken: rr.SnapToken, // rr --> relationship write response
SchemaVersion: sr.SchemaVersion, // sr --> schema write response
Depth: 50,
},
Entity: & permify_payload.Entity {
Type: "document",
Id: "1",
},
Permission: "view",
Subject: & permify_payload.Subject {
Type: "user",
Id: "3",
},
})

if (cr.can == PermissionCheckResponse_Result.RESULT_ALLOWED) {
// RESULT_ALLOWED
} else {
// RESULT_DENIED
}
```

### Streaming Calls

```go
str, err := client.Permission.LookupEntityStream(context.Background(), & permify_payload.PermissionLookupEntityRequest {
TenantId: "t1",
Metadata: & permify_payload.PermissionLookupEntityRequestMetadata {
SnapToken: rr.SnapToken, // rr --> relationship write response
SchemaVersion: sr.SchemaVersion, // sr --> schema write response
Depth: 50,
},
EntityType: "document",
Permission: "view",
Subject: & permify_payload.Subject {
Type: "user",
Id: "1",
},
})

// handle stream response
for {
res, err: = str.Recv()

if err == io.EOF {
break
}

// res.EntityId
}
```

Permify is an **open-source authorization service** for creating and maintaining fine-grained authorizations across your individual applications and services.

* [Permify website](https://permify.co)
* [Permify documentation](https://docs.permify.co/docs/)
* [Permify playground](https://play.permify.co)
* [Permify GitHub Repository](https://github.com/Permify/permify)

## Community & Support

Join our [Discord channel](https://discord.gg/MJbUjwskdH) for issues, feature requests, feedbacks or anything else. We love to talk about authorization and access control :heart:



permify | Discord


permify | Twitter


permify | Linkedin