Awesome Open Source
Awesome Open Source

Warrant Ruby Library

Use Warrant in ruby projects.

Gem Version Slack


Add this line to your application's Gemfile:

gem 'warrant'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install warrant


require 'warrant'
Warrant.api_key = 'api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E='

create_user(email, user_id = '')

This method creates a user entity in Warrant with the specified user_d. Provide an optional username to make it easier to identify users in the Warrant dashboard.

# Create user with user email and id

# Create user with generated id

create_warrant(object_type, object_id, relation, user)

User parameters

Can provide either a user id, or a combination of object type, object id, and relation


Creates a warrant for the user specified by user_id




Creates a warrant for the given userset specified by object type, object id, and relation

This method creates a warrant which specifies that the provided user (or userset) has relation on the object of type objectType with id objectId.

# Create a warrant allowing to "view" the store with id
Warrant::WarrantClient.create_warrant('store',, 'view', { user_id: })

# Create a warrant specifying all members of the manager role to "view" store of id
Warrant::WarrantClient.create_warrant('store',, 'view', { object_type: 'role', object_id: 'manager', relation: 'member' })


This method creates a session in Warrant for the user with the specified userId and returns a session token which can be used to make authorized requests to the Warrant API only for the specified user. This session token can safely be used to make requests to the Warrant API's authorization endpoint to determine user access in web and mobile client applications.

# Create session token for user

is_authorized(object_type, object_id, relation, user_id)

This method returns true if the user with the specified user_id has the specified relation to the object of type object_type with id objectId and false otherwise.

# Example: user 123 can only view store 824
Warrant::WarrantClient.is_authorized('store', '824', 'view', '123') # true
Warrant::WarrantClient.is_authorized('store', '824', 'edit', '123') # false

list_warrants(filters = {})

This method returns all warrants that match the filters provided, or all warrants for your organization if none are provided.

Filter Parameters


Only return warrants with the given object type.


Only return warrants with the given object id.


Only return warrants with the given relation.


Only return warrants with the given user id

# List all warrants for an organization

# List all warrants with object type of store
Warrant::WarrantClient.list_warrants(object_type: 'store')

We’ve used a random API key in these code examples. Replace it with your actual publishable API keys to test this code through your own Warrant account.

For more information on how to use the Warrant API, please refer to the Warrant API reference.

Note that we may release new minor and patch versions of this library with small but backwards-incompatible fixes to the type declarations. These changes will not affect Warrant itself.

Warrant Documentation

Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Ruby (221,807
Permission (11,613
Authorization (5,850
Acl (2,435
Rbac (1,373
Access Control (1,111
Abac (182
Role Based Access Control (82
Authz (78
Attribute Based Access Control (21