# info > Authen::SASL

---
type: CommandReference
command: Authen::SASL
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference

- `use Authen::SASL;` — load the module
- `$sasl = Authen::SASL->new(mechanism => '...', callback => {...});` — create SASL object
- `$conn = $sasl->client_new($service, $host, $sec);` — create client connection
- `$conn->client_start();` — start authentication
- `$conn->client_step($challenge);` — continue authentication
- `$conn->need_step()` — check if more steps needed
- `$conn->is_success()` — check success
- `use Authen::SASL qw(Perl);` — use specific implementation

## Name

Authen::SASL - SASL Authentication framework

## Synopsis

perl
use Authen::SASL;

$sasl = Authen::SASL->new(
  mechanism => 'CRAM-MD5 PLAIN ANONYMOUS',
  callback => {
    pass => \&fetch_password,
    user => $user,
  }
);
## Options

- `callback => { NAME => VALUE, ... }` — set callbacks (see Callbacks section)
- `mechanism => NAMES` or `mech => NAMES` — set the list of mechanisms (space-separated string)
- `debug => VALUE` — debug level bitmask (default 0). Bits: 1 (Perl mechanism debug), 4 (security layer package read), 8 (security layer package write)

## Methods

- `new(OPTIONS)` — constructor; arguments are shortcut for `mechanism` and `callback` methods
- `mechanism()` — returns current list of mechanisms
- `mechanism(NAMES)` — set mechanisms (space-separated string)
- `callback(NAME)` — returns the current callback for `NAME`
- `callback(NAME => VALUE, ...)` — set callbacks
- `client_new(SERVICE, HOST, SECURITY)` — creates and returns a new client connection object
- `server_new(SERVICE, HOST, OPTIONS)` — creates and returns a new server connection object
- `error()` — returns any error from the last connection

## Connection Class Methods

- `server_start(CHALLENGE)` — begin server authentication; optional client challenge
- `server_step(CHALLENGE)` — perform next server step
- `client_start()` — initial client step; returns initial value to send to server
- `client_step(CHALLENGE)` — process server challenge; returns next value to send
- `need_step()` — returns true if another step is required
- `answer(NAME)` — returns the value returned from the last call to callback `NAME`
- `property(NAME)` — returns property value for `NAME`
- `property(NAME => VALUE, ...)` — sets properties
- `service()` — returns the service argument from `*_new`
- `host()` — returns the host argument from `*_new`
- `mechanism()` — returns the name of the chosen mechanism
- `is_success()` — returns boolean indicating if authentication succeeded

## Callbacks

Callbacks can be passed as:

- **CODEREF** — called with the connection object as first argument (plus additional arguments for some callbacks)
- **ARRAYREF** — first element must be a CODEREF; called with the connection object and the remaining array elements
- **SCALAR** — used directly as the return value

## Examples

perl
use Authen::SASL;

$sasl = Authen::SASL->new(
  mechanism => 'CRAM-MD5 PLAIN ANONYMOUS',
  callback => {
    pass => \&fetch_password,
    user => $user,
  }
);
## See Also

[Authen::SASL::Perl](https://www.chedong.com/phpMan.php/perldoc/Authen%3A%3ASASL%3A%3APerl/markdown), [Authen::SASL::XS](https://www.chedong.com/phpMan.php/perldoc/Authen%3A%3ASASL%3A%3AXS/markdown), [Authen::SASL::Cyrus](https://www.chedong.com/phpMan.php/perldoc/Authen%3A%3ASASL%3A%3ACyrus/markdown)