Class: Kennedy::Granter

Inherits:
Object
Defined in:
lib/kennedy/granter.rb

Overview

Granter is used to authenticate credentials and grant tickets to services once a client has been authenticated.

Method Summary

Constructor Details

- (Granter) initialize(args = {})

A new instance of Granter

Parameters:

  • (Hash) args (defaults to: {}) — The arguments to create the granter with

Options Hash (args):

  • (String) :iv N/A — The AES-256 initialization vector to use for encryption and decryption
  • (String) :passphrase N/A — The AES-256 passphrase to use for encryption and decryption
  • (Object) :backend N/A — An instance of a backend to use for authentication

Returns:

  • (Granter) — a new instance of Granter


12
13
14
15
16
# File 'lib/kennedy/granter.rb', line 12

def initialize(args = {})
  @iv = args[:iv] || raise(ArgumentError, "Encryption IV must be given as :iv")
  @passphrase = args[:passphrase] || raise(ArgumentError, "Encryption passphrase must be given as :passphrase")
  @backend = args[:backend] || raise(ArgumentError, "Authentication backend must be given as :backend")
end

Method Details

- (true) authenticate(args = {})

Authenticates the given credentials against the current backend

Parameters:

  • (Hash) args (defaults to: {}) — The arguments to authenticate with

Options Hash (args):

  • (String) :identifier N/A — The identifier (email address, for example) to use for authentication
  • (String) :password N/A — The password to use for authentication

Returns:

  • (true, false) — A boolean indication of whether authentication was successful or not


23
24
25
# File 'lib/kennedy/granter.rb', line 23

def authenticate(args = {})
  !!@backend.authenticate(args[:identifier], args[:password])
end

- (Kennedy::Ticket) generate_ticket(args = {})

Generates a ticket object to pass back to clients requesting authentication

Parameters:

  • (Hash) args (defaults to: {}) — The arguments to generate the ticket with

Options Hash (args):

  • (String) :identifier N/A — The identifier (email address, for example) the ticket grants access for

Returns:



31
32
33
34
# File 'lib/kennedy/granter.rb', line 31

def generate_ticket(args = {})
  identifier = args[:identifier] || raise(ArgumentError, "An identifier must be given as :identifier")
  new_ticket(identifier)
end

- (Object) read_ticket(args = {})



36
37
38
39
# File 'lib/kennedy/granter.rb', line 36

def read_ticket(args = {})
  data = args[:data] || raise(ArgumentError, "Data must be given as :data")
  decrypt_ticket(args[:data])
end