Class: Kennedy::Granter

Inherits:
Object
  • Object
show all
Defined in:
lib/kennedy/granter.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Granter

Returns a new instance of Granter.

Parameters:

  • args (Hash) (defaults to: {})

    The arguments to create the granter with

Options Hash (args):

  • :iv (String)

    The AES-256 initialization vector to use for encryption and decryption

  • :passphrase (String)

    The AES-256 passphrase to use for encryption and decryption

  • :backend (Object)

    An instance of a backend to use for authentication



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

Instance Method Details

#authenticate(args = {}) ⇒ true, false

Authenticates the given credentials against the current backend

Parameters:

  • args (Hash) (defaults to: {})

    The arguments to authenticate with

Options Hash (args):

  • :identifier (String)

    The identifier (email address, for example) to use for authentication

  • :password (String)

    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

#generate_ticket(args = {}) ⇒ Kennedy::Ticket

Generates a ticket object to pass back to clients requesting authentication

Parameters:

  • args (Hash) (defaults to: {})

    The arguments to generate the ticket with

Options Hash (args):

  • :identifier (String)

    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

#read_ticket(args = {}) ⇒ Object



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