Skip to content

Commit 5dfb2de

Browse files
authored
Update README.md with Composer example
Update README.md to include a fully working example using Composer
1 parent 6de04e0 commit 5dfb2de

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,46 @@ if (isset($_SESSION['samlUserdata'])) { // If there is user data we print it.
11191119
}
11201120
```
11211121

1122+
#### Example (using Composer) that initiates the SSO request and handles the response (is the acs target) ####
1123+
1124+
Install package via composer:
1125+
```
1126+
composer require onelogin/php-saml
1127+
```
1128+
1129+
Create an index.php:
1130+
```php
1131+
<?php
1132+
require('vendor/autoload.php');
1133+
1134+
session_start();
1135+
$needsAuth = empty($_SESSION['samlUserdata']);
1136+
1137+
if ($needsAuth) {
1138+
// put SAML settings into an array to avoid placing files in the
1139+
// composer vendor/ directories
1140+
$samlsettings = array(/*...config goes here...*/);
1141+
1142+
$auth = new \OneLogin\Saml2\Auth($samlsettings);
1143+
1144+
if (!empty($_REQUEST['SAMLResponse']) && !empty($_REQUEST['RelayState'])) {
1145+
$auth->processResponse(null);
1146+
$errors = $auth->getErrors();
1147+
if (empty($errors)) {
1148+
// user has authenticated successfully
1149+
$needsAuth = false;
1150+
$_SESSION['samlUserdata'] = $auth->getAttributes();
1151+
}
1152+
}
1153+
1154+
if ($needsAuth) {
1155+
$auth->login();
1156+
}
1157+
}
1158+
1159+
// rest of your app goes here
1160+
```
1161+
11221162
#### URL-guessing methods ####
11231163

11241164
php-saml toolkit uses a bunch of methods in OneLogin_Saml2_Utils that try to guess the URL where the SAML messages are processed.

0 commit comments

Comments
 (0)