8000 GitHub - samkim/authzed-rb: An authzed client library for Ruby
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

samkim/authzed-rb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
< 8000 svg aria-hidden="true" focusable="false" class="octicon octicon-file color-fg-muted" viewBox="0 0 16 16" width="16" height="16" fill="currentColor" display="inline-block" overflow="visible" style="vertical-align:text-bottom">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authzed Ruby Client

Ruby Gems License Build Status Mailing List Discord Server Twitter

This repository houses the Ruby client library for Authzed.

Authzed is a database and service that stores, computes, and validates your application's permissions.

Developers create a schema that models their permissions requirements and use a client library, such as this one, to apply the schema to the database, insert data into the database, and query the data to efficiently check permissions in their applications.

Supported client API versions:

You can find more info on each API on the Authzed API reference documentation. Additionally, Protobuf API documentation can be found on the Buf Registry Authzed API repository.

See CONTRIBUTING.md for instructions on how to contribute and perform common tasks like building the project and running tests.

Getting Started

We highly recommend following the Protecting Your First App guide to learn the latest best practice to integrate an application with Authzed.

If you're interested in example uses of the API, see the spec files in the spec directory.

Basic Usage

Installation

This project is packaged as the gem authzed on Ruby Gems.

The command to install the library is:

gem install authzed

Initializing a client

In order to successfully connect, you will have to provide a Bearer Token with your own API Token from the Authzed dashboard in place of t_your_token_here_1234567deadbeef in the following example:

require 'authzed'


client = Authzed::Api::V1::Client.new(
    target: "localhost:50051",
    credentials: :this_channel_is_insecure,
    interceptors: [Authzed::GrpcUtil::BearerToken.new(token: "somerandomkeyhere")],
)

Performing an API call

require 'authzed'

# Is Emilia in the set of users that can read post #1?
resp = client.permissions_service.check_permission(
  Authzed::Api::V1::CheckPermissionRequest.new(
    consistency: Authzed::Api::V1::Consistency.new(
      at_least_as_fresh: Authzed::Api::V1::ZedToken.new(token: zed_token)
    ),
    resource: Authzed::Api::V1::ObjectReference.new(object_type: 'blog/post', object_id: '1'),
    permission: 'read',
    subject: Authzed::Api::V1::SubjectReference.new(
      object: Authzed::Api::V1::ObjectReference.new(object_type: 'blog/user', object_id: 'emilia')
    )
  )
)
can_read = Authzed::Api::V1::CheckPermissionResponse::Permissionship.resolve(resp.permissionship)) ==
  Authzed::Api::V1::CheckPermissionResponse::Permissionship::PERMISSIONSHIP_HAS_PERMISSION

About

An authzed client library for Ruby

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%
0