• PHP reference
  • Login

Authenticator

class Authenticator

Base class for handling custom (SSO) authentication.

Properties

string $name

The (lowercase) name of the authentication source (string - i.e.: 'imap', 'ldap', etc.). Must be unique across all of Scholica.

string $title

The display title of the Authenticator.

stdClass $options

Set values from 'sso' array (host, port, text_username, etc.).

Community $community

The current community.

Controller|null $login_controller

Note that this property is only set if the authenticator is invoked using a Authenticator Login Button, not in the normal SSO flow (e.g. using the API). Then this property will not exist in the class.

Community $site

The current community.

Methods

abstract boolean|string validate_user(string $username, string $password)

Actual authentication function, receives username and password and should return true upon successful authentication, false on failed authentication.

Parameters

  • string $username
  • string $password

Return Value

  • boolean|string

abstract get_defaults()

Get the default values for user variables (array - i.e.: username, email address, etc.).

boolean validate_exisiting(stdClass $user)

Function to check if a Model::User resource is really this SSO user.

3 return possibilities: - (bool) true - continue login with existing user - (bool) false - create a new user account - A string - cancel login and show error message

Parameters

Return Value

  • boolean

boolean after_login(User $user)

Called after successful login, allows the authenticator to update users_vars values if necessary.

Parameters

Return Value

  • boolean

boolean before_creation($user, $uservars, $community)

Called before creation, allowing to check if the user is able to get a SSO account. Should return true to continue or false to cancel/fail.

Parameters

  • $user
  • $uservars
  • $community

Return Value

  • boolean

array buttons()

Called before displaying the login screen. Provides authenticators with the possibility to add custom login action buttons.

Should always return an array (even when there are no buttons!), containing sub-arrays with the following keys:

  • (string) type: 'primary' or 'secondary'. Primary buttons are displayed like the normal 'Sign in' button whereas 'secondary' buttons are displayed next to the 'forgot password' link.
  • (string) action: internal identifier of the action, which is passed to function buttons_actions() (see below).
  • (string) title: translatable string that is title of the button.
  • (string) color (optional): HEX-string (including #!) that sets the background color of 'primary'-type buttons.

Example:

return [ [ 'type' => 'primary', // 'primary' / 'secondary' 'action' => 'facebooklogin', 'title' => l('Sign in with Facebook'), 'color' => '#3B5998' ] ];

Return Value

  • array

buttons_action(string $action)

Called after the user clicked on one of the custom buttons (see above).

Parameters

  • string $action The action identifier of the custom button