# Class: Simple Authentication and Security Layer client

Version: `@(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $`

## Contents

- Summary

- Name
- Author
- Copyright
- Version
- Purpose
- Usage

- Variables

- error
- mechanism
- encode_response

- Functions

- SetCredential
- GetCredentials
- Start
- Step

Top of the table of contents

##
- Summary

### Name

Simple Authentication and Security Layer client

### Author

Manuel Lemos (mlemos-at-acm.org)

### Copyright

Copyright © (C) Manuel Lemos 2004

### Version

@(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $

### Purpose

Provide a common interface to plug-in driver classes that implement different mechanisms for authentication used by clients of standard protocols like SMTP, POP3, IMAP, HTTP, etc.. Currently the supported authentication mechanisms are: `PLAIN`, `LOGIN`, `CRAM-MD5`, `Digest` and `NTML` (Windows or Samba).

### Usage

.

Table of contents

##
- Variables

- `error`
- `mechanism`
- `encode_response`

Table of contents

###
- error

### Type

`string`

### Default value

`''`

### Purpose

Store the message that is returned when an error occurs.

### Usage

Check this variable to understand what happened when a call to any of the class functions has failed.

This class uses cumulative error handling. This means that if one class functions that may fail is called and this variable was already set to an error message due to a failure in a previous call to the same or other function, the function will also fail and does not do anything.

This allows programs using this class to safely call several functions that may fail and only check the failure condition after the last function call.

Just set this variable to an empty string to clear the error condition.

Variables

###
- mechanism

### Type

`string`

### Default value

`''`

### Purpose

Store the name of the mechanism that was selected during the call to the `Start` function.

### Usage

You can access this variable but do not change it.

Variables

###
- encode_response

### Type

`bool`

### Default value

`1`

### Purpose

Let the drivers inform the applications whether responses need to be encoded.

### Usage

Applications should check this variable before sending authentication responses to the server to determine if the responses need to be encoded, eventually with base64 algorithm.

Variables

Table of contents

##
- Functions

- `SetCredential`
- `GetCredentials`
- `Start`
- `Step`

Table of contents

###
- SetCredential

### Synopsis

`SetCredential(`

`string` `key``,`
`string` `value`

`)`

### Purpose

Store the value of a credential that may be used by any of the supported mechanisms to process the authentication messages and responses.

### Usage

Call this function before starting the authentication dialog to pass all the credential values that be needed to use the type of authentication that the applications may need.

### Arguments

`key` - Specify the name of the credential key.

`value` - Specify the value for the credential.

Functions

###
- GetCredentials

### Synopsis

`int GetCredentials(`

`(input and output) array` `credentials``,`
`(input and output) array` `defaults``,`
`(input and output) array` `interactions`

`)`

### Purpose

Retrieve the values of one or more credentials to be used by the authentication mechanism classes.

### Usage

This is meant to be used by authentication mechanism driver classes to retrieve the credentials that may be neede.

### Arguments

`credentials` - Reference to an associative array variable with all the credentials that are being requested. The function initializes this associative array values.

`defaults` - Associative arrays with default values for credentials that may have not been defined.

`interactions` - Not yet in use. It is meant to provide context information to retrieve credentials that may be obtained interacting with the user.

### Return value

The function may return `SASL_CONTINUE` if it succeeded, or `SASL_NOMECH` if it was not possible to retrieve one of the requested credentials.

Functions

###
- Start

### Synopsis

`int Start(`

`(input and output) array` `mechanisms``,`
`(output) string &` `message``,`
`(input and output) array` `interactions`

`)`

### Purpose

Process the initial authentication step initializing the driver class that implements the first of the list of requested mechanisms that is supported by this SASL client library implementation.

### Usage

Call this function specifying a list of mechanisms that the server supports. If the `message` argument returns a string, it should be sent to the server as initial message. Check the `encode_response` variable to determine whether the initial message needs to be encoded, eventually with base64 algorithm, before it is sent to the server.

### Arguments

`mechanisms` - Define the list of names of authentication mechanisms supported by the that should be tried.

`message` - Return the initial message that should be sent to the server to start the authentication dialog. If this value is undefined, no message should be sent to the server.

`interactions` - Not yet in use. It is meant to provide context information to interact with the end user.

### Return value

The function may return `SASL_CONTINUE` if it could start one of the requested authentication mechanisms. It may return `SASL_NOMECH` if it was not possible to start any of the requested mechanisms. It returns `SASL_FAIL` or other value in case of error.

Functions

###
- Step

### Synopsis

`int Step(`

`string` `response``,`
`(output) string &` `message``,`
`(input and output) array` `interactions`

`)`

### Purpose

Process the authentication steps after the initial step, until the authetication iteration dialog is complete.

### Usage

Call this function iteratively after a successful initial step calling the `Start` function.

### Arguments

`response` - Pass the response returned by the server to the previous step.

`message` - Return the message that should be sent to the server to continue the authentication dialog. If this value is undefined, no message should be sent to the server.

`interactions` - Not yet in use. It is meant to provide context information to interact with the end user.

### Return value

The function returns `SASL_CONTINUE` if step was processed successfully, or returns `SASL_FAIL` in case of error.

Functions

Table of contents