Skip to content

Commit 09a38ce

Browse files
authored
Merge pull request #230 from glensc/codereview
codereview fixes
2 parents 30d7251 + 0d6df77 commit 09a38ce

14 files changed

Lines changed: 55 additions & 66 deletions

File tree

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ unset($_SESSION['AuthNRequestID']);
726726
$errors = $auth->getErrors();
727727

728728
if (!empty($errors)) {
729-
print_r('<p>'.implode(', ', $errors).'</p>');
729+
echo '<p>', implode(', ', $errors), '</p>';
730730
exit();
731731
}
732732

@@ -865,9 +865,9 @@ $auth->processSLO(false, $requestID);
865865
$errors = $auth->getErrors();
866866

867867
if (empty($errors)) {
868-
print_r('Sucessfully logged out');
868+
echo 'Sucessfully logged out';
869869
} else {
870-
print_r(implode(', ', $errors));
870+
echo implode(', ', $errors);
871871
}
872872
```
873873

@@ -1009,7 +1009,7 @@ if (isset($_SESSION['samlNameIdFormat'])) {
10091009
$nameIdFormat = $_SESSION['samlNameIdFormat'];
10101010
}
10111011
$auth->logout($returnTo, $paramters, $nameId, $sessionIndex, false, $nameIdFormat);
1012-
```
1012+
```
10131013

10141014
If a match on the future LogoutResponse ID and the LogoutRequest ID to be sent is required, that LogoutRequest ID must to be extracted and stored.
10151015

@@ -1037,8 +1037,7 @@ session_start(); // Initialize the session, we do that because
10371037
// Note that processResponse and processSLO
10381038
// methods could manipulate/close that session
10391039

1040-
require_once dirname(dirname(__FILE__)).'/_toolkit_loader.php'; // Load Saml2 and
1041-
// external libs
1040+
require_once dirname(__DIR__).'/_toolkit_loader.php'; // Load Saml2 and external libs
10421041
require_once 'settings.php'; // Load the setting info as an Array
10431042

10441043
$auth = new OneLogin_Saml2_Auth($settingsInfo); // Initialize the SP SAML instance
@@ -1059,7 +1058,7 @@ if (isset($_GET['sso'])) { // SSO action. Will send an AuthNRequest to the I
10591058
// that could took place during the process
10601059

10611060
if (!empty($errors)) {
1062-
print_r('<p>'.implode(', ', $errors).'</p>');
1061+
echo '<p>', implode(', ', $errors), '</p>';
10631062
}
10641063
// This check if the response was
10651064
if (!$auth->isAuthenticated()) { // sucessfully validated and the user
@@ -1075,9 +1074,9 @@ if (isset($_GET['sso'])) { // SSO action. Will send an AuthNRequest to the I
10751074
$auth->processSLO(); // Process the Logout Request & Logout Response
10761075
$errors = $auth->getErrors(); // Retrieves possible validation errors
10771076
if (empty($errors)) {
1078-
print_r('<p>Sucessfully logged out</p>');
1077+
echo '<p>Sucessfully logged out</p>';
10791078
} else {
1080-
print_r('<p>'.implode(', ', $errors).'</p>');
1079+
echo '<p>', implode(', ', $errors), '</p>';
10811080
}
10821081
}
10831082

_toolkit_loader.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
// Create an __autoload function
3+
// Create an __autoload function
44
// (can conflicts other autoloaders)
55
// http://php.net/manual/en/language.oop5.autoload.php
66

7-
$libDir = dirname(__FILE__) . '/lib/Saml2/';
8-
$extlibDir = dirname(__FILE__) . '/extlib/';
7+
$libDir = __DIR__ . '/lib/Saml2/';
8+
$extlibDir = __DIR__ . '/extlib/';
99

1010
// Load composer
11-
if (file_exists('vendor/autoload.php')) {
12-
require 'vendor/autoload.php';
11+
if (file_exists(__DIR__ .'/vendor/autoload.php')) {
12+
require __DIR__ . '/vendor/autoload.php';
1313
}
1414

1515
// Load now external libs
@@ -20,6 +20,6 @@
2020
foreach ($folderInfo as $element) {
2121
if (is_file($libDir.$element) && (substr($element, -4) === '.php')) {
2222
include_once $libDir.$element;
23+
break;
2324
}
2425
}
25-

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"name": "onelogin/php-saml",
33
"description": "OneLogin PHP SAML Toolkit",
44
"license": "MIT",
5-
"version": "2.11.0",
6-
"homepage": "https://onelogin.zendesk.com/hc/en-us/sections/200245634-SAML-Toolkits",
5+
"homepage": "https://developers.onelogin.com/saml/php",
76
"keywords": ["saml", "saml2", "onelogin"],
87
"autoload": {
98
"classmap": [
@@ -19,6 +18,7 @@
1918
},
2019
"require": {
2120
"php": ">=5.3.2",
21+
"ext-curl": "*",
2222
"ext-openssl": "*",
2323
"ext-dom": "*",
2424
"ext-mcrypt": "*"
@@ -32,8 +32,6 @@
3232
"squizlabs/php_codesniffer": "2.9.0"
3333
},
3434
"suggest": {
35-
"lib-openssl": "Install openssl lib in order to handle with x509 certs (require to support sign and encryption)",
36-
"ext-mcrypt": "Install mcrypt and php5-mcrypt libs in order to support encryption",
3735
"ext-gettext": "Install gettext and php5-gettext libs to handle translations"
3836
}
3937
}

demo1/index.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
2-
32
/**
43
* SAML Handler
54
*/
65

76
session_start();
87

9-
require_once dirname(dirname(__FILE__)).'/_toolkit_loader.php';
8+
require_once dirname(__DIR__).'/_toolkit_loader.php';
109

1110
require_once 'settings.php';
1211

@@ -65,7 +64,7 @@
6564
$errors = $auth->getErrors();
6665

6766
if (!empty($errors)) {
68-
print_r('<p>'.implode(', ', $errors).'</p>');
67+
echo '<p>',implode(', ', $errors),'</p>';
6968
}
7069

7170
if (!$auth->isAuthenticated()) {
@@ -91,9 +90,9 @@
9190
$auth->processSLO(false, $requestID);
9291
$errors = $auth->getErrors();
9392
if (empty($errors)) {
94-
print_r('<p>Sucessfully logged out</p>');
93+
echo '<p>Sucessfully logged out</p>';
9594
} else {
96-
print_r('<p>'.implode(', ', $errors).'</p>');
95+
echo '<p>', implode(', ', $errors), '</p>');
9796
}
9897
}
9998

demo1/metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SAML Metadata view
55
*/
66

7-
require_once dirname(dirname(__FILE__)).'/_toolkit_loader.php';
7+
require_once dirname(__DIR__).'/_toolkit_loader.php';
88

99
require_once 'settings.php' ;
1010

endpoints/acs.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2-
2+
33
/**
44
* SP Assertion Consumer Service Endpoint
55
*/
66

77
session_start();
88

9-
require_once dirname(dirname(__FILE__)).'/_toolkit_loader.php';
9+
require_once dirname(__DIR__).'/_toolkit_loader.php';
1010

1111
$auth = new OneLogin_Saml2_Auth();
1212

@@ -15,7 +15,7 @@
1515
$errors = $auth->getErrors();
1616

1717
if (!empty($errors)) {
18-
print_r('<p>'.implode(', ', $errors).'</p>');
18+
echo '<p>', implode(', ', $errors), '</p>';
1919
exit();
2020
}
2121

endpoints/metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SP Metadata Endpoint
55
*/
66

7-
require_once dirname(dirname(__FILE__)).'/_toolkit_loader.php';
7+
require_once dirname(__DIR__).'/_toolkit_loader.php';
88

99
try {
1010
$auth = new OneLogin_Saml2_Auth();

endpoints/sls.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
2-
32
/**
43
* SP Single Logout Service Endpoint
54
*/
65

76
session_start();
87

9-
require_once dirname(dirname(__FILE__)).'/_toolkit_loader.php';
8+
require_once dirname(__DIR__).'/_toolkit_loader.php';
109

1110
$auth = new OneLogin_Saml2_Auth();
1211

@@ -15,7 +14,7 @@
1514
$errors = $auth->getErrors();
1615

1716
if (empty($errors)) {
18-
print_r('Sucessfully logged out');
17+
echo 'Sucessfully logged out';
1918
} else {
20-
print_r(implode(', ', $errors));
19+
echo implode(', ', $errors);
2120
}

lib/Saml/AuthRequest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ protected function _generateUniqueID()
5656
*/
5757
protected function _getTimestamp()
5858
{
59-
$defaultTimezone = date_default_timezone_get();
60-
date_default_timezone_set('UTC');
61-
$timestamp = strftime("%Y-%m-%dT%H:%M:%SZ");
62-
date_default_timezone_set($defaultTimezone);
59+
$date = new DateTime('now', new DateTimeZone('UTC'));
60+
$timestamp = $date->format("Y-m-d\TH:i:s\Z");
6361
return $timestamp;
6462
}
6563
}

lib/Saml/Metadata.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ public function getXml()
3030
*/
3131
protected function _getMetadataValidTimestamp()
3232
{
33-
$timeZone = date_default_timezone_get();
34-
date_default_timezone_set('UTC');
35-
$time = strftime("%Y-%m-%dT%H:%M:%SZ", time() + self::VALIDITY_SECONDS);
36-
date_default_timezone_set($timeZone);
33+
$timestamp = time() + self::VALIDITY_SECONDS;
34+
$date = new DateTime("@$timestamp", new DateTimeZone('UTC'));
35+
$time = $date->format("Y-m-d\TH:i:s\Z");
3736
return $time;
3837
}
3938
}

0 commit comments

Comments
 (0)