SDKs overview

Warrant provides Software Development Kits (SDKs) to facilitate the integration of its authorization service into various applications. These SDKs are designed to abstract the underlying RESTful API interactions, allowing developers to manage authorization policies, objects, and sessions using idiomatic code in their preferred programming languages. The SDKs enable tasks such as defining access rules, checking permissions, and managing multi-tenant authorization contexts Warrant official documentation. By utilizing these libraries, developers can embed fine-grained access control mechanisms without directly handling HTTP requests or JSON parsing.

The SDKs streamline common authorization patterns, including Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC), which are foundational for many modern application security models OAuth 2.0 grant types explanation. They are built to interact with Warrant's core API, which handles the evaluation of authorization policies at scale. This approach aims to reduce the operational overhead associated with building and maintaining a custom authorization system.

Official SDKs by language

Warrant maintains official SDKs for several popular programming languages, ensuring direct support and ongoing updates for developers. These SDKs are the recommended method for integrating Warrant into applications due to their direct alignment with the service's API and features. Each SDK is typically distributed through its respective language's standard package manager.

Language Package/Repository Maturity Description
Go go-warrant Stable Provides Go-idiomatic interfaces for interacting with the Warrant API.
Java warrant-java Stable A Java client library for managing authorization policies and checks.
JavaScript @warrantdev/warrant-js Stable Client-side JavaScript SDK for web applications, often used in conjunction with Node.js.
Node.js @warrantdev/warrant-node Stable Server-side Node.js SDK for backend authorization logic.
Python warrant Stable Pythonic client for integrating Warrant into Python applications.
Ruby warrant-ruby Stable Ruby Gem for interacting with the Warrant API in Ruby applications.
PHP warrant-php Stable PHP client library for authorization management.
C# Warrant.Net Stable .NET client library for C# applications.

Installation

Installing Warrant SDKs typically involves using the package manager specific to each programming language. The following examples demonstrate the installation process for some of the widely used SDKs, as detailed in the Warrant SDKs documentation.

Node.js / JavaScript

For Node.js projects, the SDK can be installed via npm or yarn:

npm install @warrantdev/warrant-node
# or
yarn add @warrantdev/warrant-node

Python

Python developers can install the SDK using pip:

pip install warrant

Go

Go projects integrate the SDK using go get:

go get github.com/warrantdev/go-warrant

Java

For Maven-based Java projects, add the dependency to your pom.xml file:

<dependency>
    <groupId>dev.warrant</groupId>
    <artifactId>warrant-java</artifactId>
    <version>1.0.0</version> <!-- Use the latest version -->
</dependency>

For Gradle projects, add the dependency to your build.gradle file:

implementation 'dev.warrant:warrant-java:1.0.0' // Use the latest version

PHP

PHP projects use Composer for installation:

composer require warrantdev/warrant-php

Ruby

Ruby projects install the Gem:

gem install warrant-ruby

C#

For .NET projects, use the NuGet Package Manager:

dotnet add package Warrant.Net

Quickstart example

The following example demonstrates a basic authorization check using the Warrant Node.js SDK. This snippet illustrates how to initialize the client, define an object, and perform an access check. A comprehensive guide with additional examples is available in the Warrant Getting Started guide.

Node.js Quickstart

This example checks if a user has permission to 'view' a specific 'document'.

const WarrantClient = require('@warrantdev/warrant-node');

// Initialize the Warrant client with your API Key
const warrant = new WarrantClient({
    apiKey: process.env.WARRANT_API_KEY
});

async function checkAccess() {
    try {
        // Create a user if they don't exist
        await warrant.createUser({
            userId: 'user-id-123'
        });

        // Create a document if it doesn't exist
        await warrant.createObject('document', 'doc-id-abc', {
            name: 'Important Document'
        });

        // Assign the user as a 'viewer' of the document
        await warrant.createAuthorization(
            'document',
            'doc-id-abc',
            'viewer',
            'user',
            'user-id-123'
        );

        // Check if user-id-123 can 'view' document-id-abc
        const hasAccess = await warrant.check({
            object: {
                objectType: 'document',
                objectId: 'doc-id-abc'
            },
            relation: 'viewer',
            subject: {
                objectType: 'user',
                objectId: 'user-id-123'
            }
        });

        if (hasAccess) {
            console.log('User has permission to view the document.');
        } else {
            console.log('User does NOT have permission to view the document.');
        }
    } catch (error) {
        console.error('Error during authorization check:', error);
    }
}

checkAccess();

Python Quickstart

The Python equivalent for checking access permissions:

import os
from warrant import WarrantClient

# Initialize the Warrant client with your API Key
warrant = WarrantClient(api_key=os.environ.get("WARRANT_API_KEY"))

async def check_access():
    try:
        # Create a user if they don't exist
        await warrant.create_user(user_id="user-id-123")

        # Create a document if it doesn't exist
        await warrant.create_object("document", "doc-id-abc", {"name": "Important Document"})

        # Assign the user as a 'viewer' of the document
        await warrant.create_authorization(
            "document",
            "doc-id-abc",
            "viewer",
            "user",
            "user-id-123"
        )

        # Check if user-id-123 can 'view' document-id-abc
        has_access = await warrant.check(
            object_type="document",
            object_id="doc-id-abc",
            relation="viewer",
            subject_type="user",
            subject_id="user-id-123"
        )

        if has_access:
            print("User has permission to view the document.")
        else:
            print("User does NOT have permission to view the document.")
    except Exception as e:
        print(f"Error during authorization check: {e}")

# For synchronous execution in a non-async context:
import asyncio
asyncio.run(check_access())

Community libraries

While Warrant provides a robust set of official SDKs, the open-source nature of many development ecosystems sometimes leads to the creation of community-maintained libraries. These libraries can offer different paradigms, integrations with specific frameworks, or additional utilities not present in the official SDKs. Developers often contribute to these projects to address niche use cases or experiment with alternative approaches to authorization integration. However, it is important to note that community libraries may not always have the same level of support, maintenance, or feature parity as official offerings. Warrant's documentation primarily focuses on its official SDKs, and while community contributions are valued, their stability and currency can vary. Developers considering community libraries should review their recent activity, issue tracker, and maintainer engagement. As of this writing, specific widely adopted community libraries for Warrant are not extensively documented on its public channels, indicating a strong focus on the official SDKs Warrant's SDKs page.

For developers looking to contribute or explore community efforts, examining platforms like GitHub for repositories tagged with "warrant" or "authorization" in conjunction with specific language names can be a starting point. Such repositories might host unofficial wrappers, plugins, or examples that extend the functionality of the official SDKs. For example, developers building on frameworks might look for integrations that streamline the setup of authorization checks within a specific framework's lifecycle. An example of a similar community-driven approach can be seen in the broader API ecosystem where unofficial SDKs and connectors extend platform reach, as documented by Tray.io's API integration list.