Zero Authentication Service - Ruby Client

This is a ruby client libraty for the Zero Authentication Service (https://github.com/zero-as/zas-service).

Usage

Generally:

client = Zas::Client.new
auth_result = client.authenticate(Zas::Credentials.new(:username => 'john', :password => 'letmein'))
p "You are authenticated" if auth_result.authenticated?

For HTTP Basic Auth

# everything from general usage
require 'zas/http_basic_credentials'
auth_result = client.authenticate(Zas::HttpBasicCredentials.new('Zm9vOmJhcg=='))
p "You've been authenticated" if auth_result.authenticated?

In irb:

bundle exec irb -Ilib -rzas
=> # everything from general usage

Adding Support for Other Credential Types

Any object that responds to #to_wire may be based to Client#authenticate. The wire format is JSON and includes a strategy key/value pair and a credentials key/value pair. For example, here is what a simple authentication wire representation looks like:

{
  "strategy": "auth",
  "credentials": {
    "username": "jdoe",
    "password": "password"
  }
}

Here is an example of what a custom authentication type might look like:

{
  "strategy": "my_auth",
  "credentials": {
    "id": "my_identifier",
    "token": "123456gregergjerg"
  }
}

In order to handle a custom strategy you will need to register an authenticator when starting up your Zas service.

Configuration

config = Zas::ClientConfiguration.new(:name => 'my-client')
client = Zas::Client.new(config)

Notes

  • Zas::Client is not threadsafe
  • When using in irb call client.disconnect or CTRL-C to exit