WiseLoop PHP REST Services 3.3.1
RESTful web service API framework for PHP
wlAuthHandler Class Reference
Inheritance diagram for wlAuthHandler:

Public Member Functions

 __construct ()
 isAuthorized ($request)
 authenticate ($authData)
 set ($authData)
 get ($fieldName=null)
 clear ()

Protected Attributes

 $_session
 $_key

Detailed Description

WiseLoop AuthHandler class definition
This is the base class for defining authentication & authorization handlers.
In order to add security support for an API, one should define an auth handler by extending this class that will describe the authentication & authorization mechanisms for the API:

class myAuthHandler extends wlAuthHandler {
    public function authenticate($authData){
        //authenticate $authData and array or an object that should contain the username and password to be authenticated
    }
    public function isAuthorized($request) {
        //authorize the $request
    }
}

A real auth handler should be derived from wlAuthHandler and should overwrite wlAuthHandler::authenticate and wlAuthHandler::isAuthorized methods.
To enable authentication, the auth handler must be instantiated and used inside wlRestControllerAuth that should be registered in within the service and to enable authorization it must be used inside a trigger registered in the service at request time:

$authHandler = new myAuthHandler();
$service->registerController(new wlRestControllerAuth($authHandler));
$service->registerTrigger(new wlRestTriggerAuth($authHandler), wlRestTrigger::ON_REQUEST_EVENT);
Author:
WiseLoop

See also: Authentication & Authorization


Constructor & Destructor Documentation

__construct ( )

Constructor.
Creates a wlAuthHandler object.


Member Function Documentation

authenticate ( authData)

This method should be overwritten in the derived classes and describes how to authenticate a certain user.

Parameters:
array | mixed$authDatathe data (user information - usually userName and password) that needs to be authenticated
Returns:
mixed

Reimplemented in wlAuthHandlerPdo, and wlAuthHandlerUsernameAndPassword.

clear ( )

Clears the authentication data from the session.
This should be used when logging-out.

get ( fieldName = null)

Gets the authentication data from the session.

Parameters:
string | null$fieldNameif specified only a that field of the auth data (user information) will be returned
Returns:
mixed|null
isAuthorized ( request)

This method should be overwritten in the derived classes and describes how to authorize a request.

Parameters:
wlRestRequest$requestthe current request
Returns:
bool

Reimplemented in wlAuthHandlerPdo, and wlAuthHandlerUsernameAndPassword.

set ( authData)

Sets the authentication data for the current session.
This is happening only after a successful authentication.

Parameters:
mixed$authDatathe authentication data
Returns:
mixed the authentication data if the session set was a success or null if not

Field Documentation

$_key [protected]

Type: string the session key

$_session [protected]

Type: wlSession the session data object

 All Data Structures Functions Variables