Skip to content
britishtea edited this page Feb 13, 2013 · 2 revisions

Basics

Cinch-authentication can be configured globally and on a per-plugin basis. To configure globally:

bot = Cinch::Bot.new do
  configure do |c|
    # ...
    
    c.authentication          = Cinch::Configuration::Authentication.new
    c.authentication.strategy = :channel_status # or :list / :login
    c.authentication.level    = :o
  end
end

To configure it on a per-plugin basis:

bot = Cinch::Bot.new do
  configure do |c|
    # ...

    c.plugins.plugins << Admin
    c.plugins.options[Admin] = {
      :authentication_strategy => :channel_status
      :authentication_level    => :o
    }
  end
end

Plugin settings always trump global settings, so you can safely configure some basic settings and use different settings for specific plugins.

Required settings

Cinch-authentication requires two settings to be configured: strategy and level. Note that when configuring a plugin, the names of these settings are prefixed with authentication_ (see the examples above).

The level settings can be an Array (e.g. [:admins, :users]) when the strategy is :list or :login.

Optional settings.

The :channel_status strategy

  • channel: The name of the channel where the statuses are pulled from. The channel defaults to the channel the message was sent on.

The :list strategy

None.

The :login strategy

When using the :login strategy, cinch-authentication needs to know how to create, fetch and check users for their level. This is done by configuring lambdas.

  • registration: A lambda that registers a new user. It takes two arguments: a nickname String and a password String. The lambda should return false if registering a new user fails.
    c.authentication.registration = lambda { |nickname, password|
      User.create :nickname => nickname, :password => password
    }
  • fetch_user: A lambda that fetches a user by nickname. It should take one argument: a nickname String. Note that the returned user object should have an authenticate instance method.
    c.authentication.fetch_user = lambda { |nickname|
      User.first :nickname => nickname
    }
  • For each level there should be a lambda that checks if a user has a certain level. The lambda should take one argument: a user instance. The lambda should return a Boolean.
    c.authentication.admins = lambda { |user| user.type == 'admin' } 
    c.authentication.users  = lambda { |user| user.type == 'user' }