PHPackages                             krthkbharadwaj/php-custom-one-login - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. krthkbharadwaj/php-custom-one-login

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

krthkbharadwaj/php-custom-one-login
===================================

OneLogin PHP SAML Toolkit

v1.0.9(5y ago)06MITPHPPHP &gt;=5.4

Since Jun 12Pushed 4y agoCompare

[ Source](https://github.com/krthkbharadwaj/php-custom-one-login)[ Packagist](https://packagist.org/packages/krthkbharadwaj/php-custom-one-login)[ Docs](https://developers.onelogin.com/saml/php)[ RSS](/packages/krthkbharadwaj-php-custom-one-login/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (11)Used By (0)

OneLogin's SAML PHP Toolkit Compatible with PHP 5.X &amp; 7.X
=============================================================

[](#onelogins-saml-php-toolkit-compatible-with-php-5x--7x)

[![Build Status](https://camo.githubusercontent.com/e4ebdaa292e3f6a42439b7c500922fb7d011db500bfedd8d7049c193dad4c125/68747470733a2f2f6170692e7472617669732d63692e6f72672f6f6e656c6f67696e2f7068702d73616d6c2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/onelogin/php-saml) [![Coverage Status](https://camo.githubusercontent.com/59dff5179be7de8d8ab79adadd1d288edb247c21c499c090bab5895eee1ced80/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6f6e656c6f67696e2f7068702d73616d6c2f62616467652e706e67)](https://coveralls.io/r/onelogin/php-saml) [![License](https://camo.githubusercontent.com/60096986c5ca8b0c33cb85822de1d690b8e34516d010a8bef1919000beb82b71/68747470733a2f2f706f7365722e707567782e6f72672f6f6e656c6f67696e2f7068702d73616d6c2f6c6963656e73652e706e67)](https://packagist.org/packages/onelogin/php-saml)

Add SAML support to your PHP software using this library. Forget those complicated libraries and use this open source library provided and supported by OneLogin Inc.

Warning
-------

[](#warning)

This version is compatible with PHP 7.X and does not include xmlseclibs (you will need to install it via composer, dependency described in composer.json)

Security Guidelines
-------------------

[](#security-guidelines)

If you believe you have discovered a security vulnerability in this toolkit, please report it at  with a description. We follow responsible disclosure guidelines, and will work with you to quickly find a resolution.

Why add SAML support to my software?
------------------------------------

[](#why-add-saml-support-to-my-software)

SAML is an XML-based standard for web browser single sign-on and is defined by the OASIS Security Services Technical Committee. The standard has been around since 2002, but lately it is becoming popular due its advantages:

- **Usability** - One-click access from portals or intranets, deep linking, password elimination and automatically renewing sessions make life easier for the user.
- **Security** - Based on strong digital signatures for authentication and integrity, SAML is a secure single sign-on protocol that the largest and most security conscious enterprises in the world rely on.
- **Speed** - SAML is fast. One browser redirect is all it takes to securely sign a user into an application.
- **Phishing Prevention** - If you don’t have a password for an app, you can’t be tricked into entering it on a fake login page.
- **IT Friendly** - SAML simplifies life for IT because it centralizes authentication, provides greater visibility and makes directory integration easier.
- **Opportunity** - B2B cloud vendor should support SAML to facilitate the integration of their product.

General description
-------------------

[](#general-description)

OneLogin's SAML PHP toolkit let you build a SP (Service Provider) over your PHP application and connect it to any IdP (Identity Provider).

Supports:

- SSO and SLO (SP-Initiated and IdP-Initiated).
- Assertion and nameId encryption.
- Assertion signature.
- Message signature: AuthNRequest, LogoutRequest, LogoutResponses.
- Enable an Assertion Consumer Service endpoint.
- Enable a Single Logout Service endpoint.
- Publish the SP metadata (which can be signed).

Key features:

- **saml2int** - Implements the SAML 2.0 Web Browser SSO Profile.
- **Session-less** - Forget those common conflicts between the SP and the final app, the toolkit delegate session in the final app.
- **Easy to use** - Programmer will be allowed to code high-level and low-level programming, 2 easy to use APIs are available.
- **Tested** - Thoroughly tested.
- **Popular** - OneLogin's customers use it. Many PHP SAML plugins uses it.

Integrate your PHP toolkit at OneLogin using this guide:

Installation
------------

[](#installation)

### Dependencies

[](#dependencies)

- `php >= 5.4` and some core extensions like `php-xml`, `php-date`, `php-zlib`.
- `openssl`. Install the openssl library. It handles x509 certificates.
- `gettext`. Install that library and its php driver. It handles translations.
- `curl`. Install that library and its php driver if you plan to use the IdP Metadata parser.

### Code

[](#code)

#### Option 1. Download from github

[](#option-1-download-from-github)

The toolkit is hosted on github. You can download it from:

-

Search for 3.X.X releases

Copy the core of the library inside the php application. (each application has its structure so take your time to locate the PHP SAML toolkit in the best place). See the "Guide to add SAML support to my app" to know how.

#### Option 2. Composer

[](#option-2-composer)

The toolkit supports [composer](https://getcomposer.org/). You can find the `onelogin/php-saml` package at

In order to import the saml toolkit to your current php project, execute

```
composer require onelogin/php-saml

```

Remember to select the 3.X.X branch

After installation has completed you will find at the `vendor/` folder a new folder named `onelogin` and inside the `php-saml`. Make sure you are including the autoloader provided by composer. It can be found at `vendor/autoload.php`.

**Important** In this option, the x509 certs must be stored at `vendor/onelogin/php-saml/certs`and settings file stored at `vendor/onelogin/php-saml`.

Your settings are at risk of being deleted when updating packages using `composer update` or similar commands. So it is **highly** recommended that instead of using settings files, you pass the settings as an array directly to the constructor (explained later in this document). If you do not use this approach your settings are at risk of being deleted when updating packages using `composer update` or similar commands.

Compatibility
-------------

[](#compatibility)

This 3.X.X supports PHP 7.X. but can be used with PHP &gt;=5.4 as well (5.6.24+ recommended for security reasons).

Namespaces
----------

[](#namespaces)

If you are using the library with a framework like Symfony that contains namespaces, remember that calls to the class must be done by adding a backslash (`\`) to the start, for example to use the static method getSelfURLNoQuery use:

```
\OneLogin\Saml2\Utils::getSelfURLNoQuery()

```

Security warning
----------------

[](#security-warning)

In production, the `strict` parameter **MUST** be set as `"true"` and the `signatureAlgorithm` and `digestAlgorithm` under `security` must be set to something other than SHA1 (see  ). Otherwise your environment is not secure and will be exposed to attacks.

In production also we highly recommended to register on the settings the IdP certificate instead of using the fingerprint method. The fingerprint, is a hash, so at the end is open to a collision attack that can end on a signature validation bypass. Other SAML toolkits deprecated that mechanism, we maintain it for compatibility and also to be used on test environment.

Getting started
---------------

[](#getting-started)

### Knowing the toolkit

[](#knowing-the-toolkit)

The new OneLogin SAML Toolkit contains different folders (`certs`, `endpoints`, `lib`, `demo`, etc.) and some files.

Let's start describing the folders:

#### `certs/`

[](#certs)

SAML requires a x509 cert to sign and encrypt elements like `NameID`, `Message`, `Assertion`, `Metadata`.

If our environment requires sign or encrypt support, this folder may contain the x509 cert and the private key that the SP will use:

- `sp.crt` - The public cert of the SP
- `sp.key` - The private key of the SP

Or also we can provide those data in the setting file at the `$settings['sp']['x509cert']`and the `$settings['sp']['privateKey']`.

Sometimes we could need a signature on the metadata published by the SP, in this case we could use the x509 cert previously mentioned or use a new x.509 cert: `metadata.crt` and `metadata.key`.

Use `sp_new.crt` if you are in a key rollover process and you want to publish that x509 certificate on Service Provider metadata.

#### `src/`

[](#src)

This folder contains the heart of the toolkit, the libraries:

- `Saml2` folder contains the new version of the classes and methods that are described in a later section.

#### `doc/`

[](#doc)

This folder contains the API documentation of the toolkit.

#### `endpoints/`

[](#endpoints)

The toolkit has three endpoints:

- `metadata.php` - Where the metadata of the SP is published.
- `acs.php` - Assertion Consumer Service. Processes the SAML Responses.
- `sls.php` - Single Logout Service. Processes Logout Requests and Logout Responses.

You can use the files provided by the toolkit or create your own endpoints files when adding SAML support to your applications. Take in mind that those endpoints files uses the setting file of the toolkit's base folder.

#### `locale/`

[](#locale)

Locale folder contains some translations: `en_US` and `es_ES` as a proof of concept. Currently there are no translations but we will eventually localize the messages and support multiple languages.

#### Other important files

[](#other-important-files)

- `settings_example.php` - A template to be used in order to create a settings.php file which contains the basic configuration info of the toolkit.
- `advanced_settings_example.php` - A template to be used in order to create a advanced\_settings.php file which contains extra configuration info related to the security, the contact person, and the organization associated to the SP.
- `_toolkit_loader.php` - This file load the toolkit libraries (The SAML2 lib).

#### Miscellaneous

[](#miscellaneous)

- `tests/` - Contains the unit test of the toolkit.
- `demo1/` - Contains an example of a simple PHP app with SAML support. Read the `Readme.txt` inside for more info.
- `demo2/` - Contains another example.

### How it works

[](#how-it-works)

#### Settings

[](#settings)

First of all we need to configure the toolkit. The SP's info, the IdP's info, and in some cases, configure advanced security issues like signatures and encryption.

There are two ways to provide the settings information:

- Use a `settings.php` file that we should locate at the base folder of the toolkit.
- Use an array with the setting data and provide it directly to the constructor of the class.

There is a template file, `settings_example.php`, so you can make a copy of this file, rename and edit it.

```
