# AuthStack SAML 2.0 Service Provider library

Use this library to implement SAML 2.0 Service Provider side at your web / app.

## Installation

`composer require authstack/saml-service-provider`

### With Laravel

A service provider is included for use with Laravel.

## Configuration

## Use

### Creating Authentication Request (AuthN)

To initiate single-sign on, you have to create authentication (AuthN) request.

If your configuration checks out, to create AuthN request and send it to IdP:

```php
<?php

use AuthStack\SAMLServiceProvider\Model\AuthN;

$authn = new AuthN(true); // 'true' means we want to create AuthenticationRequest LightSaml object

$authn->send();
```

### Receiving and validating Authentication response

```php
<?php

use AuthStack\SAMLServiceProvider\Model\AuthN;
use AuthStack\SAMLServiceProvider\Exceptions\SAMLException;

$authn = new AuthN();

try
{
    // Receive and validate. If validation fails, SAMLException will be thrown with appropriate message
    $authn->receive()->validate();
}
catch(SAMLException $e)
{
    echo $e->getMessage();
}

// Response is an instance of LightSaml\Model\Protocol\Response
$response = $authn->getResponse();

```
