Skip to content

Commit eae1e4f

Browse files
authored
Merge pull request #12 from Staffbase/NFS-616-dependency-update
NFS-616: update deps, fixes tests
2 parents c6a5adc + f6d4bcb commit eae1e4f

8 files changed

Lines changed: 420 additions & 444 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dist: trusty
22
sudo: false
33
language: php
44
php:
5-
- '5.6'
5+
- '7.4'
66
install:
77
- composer install
88
script:

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.5.9",
15+
"php": "^7.3",
1616
"lcobucci/jwt": "^3.2"
1717

1818
},
1919
"require-dev": {
20-
"cvuorinen/phpdoc-markdown-public": "^0.1.2",
20+
"cvuorinen/phpdoc-markdown-public": "^0.2.0",
2121
"phpseclib/phpseclib": "^2.0",
22-
"phpunit/phpunit": "^4.8"
22+
"phpunit/phpunit": "^9.0"
2323
},
2424
"autoload": {
2525
"psr-4": {

phpunit.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" name="unit" bootstrap="vendor/autoload.php">
2+
<phpunit colors="true" bootstrap="vendor/autoload.php">
33
<testsuites>
44
<testsuite name="Plugins SDK unit test suite">
55
<file>test/SSODataTest.php</file>
66
<file>test/SSOTokenTest.php</file>
77
<file>test/PluginSessionTest.php</file>
88
</testsuite>
9+
910
</testsuites>
11+
<filter>
12+
<whitelist processUncoveredFilesFromWhitelist="true">
13+
<directory suffix=".php">src</directory>
14+
</whitelist>
15+
</filter>
1016
</phpunit>

src/PluginSession.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
namespace Staffbase\plugins\sdk;
1616

1717
use SessionHandlerInterface;
18-
use Staffbase\plugins\sdk\SSOData;
19-
use Staffbase\plugins\sdk\SSOToken;
2018
use Staffbase\plugins\sdk\Exceptions\SSOException;
2119
use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException;
2220
use Staffbase\plugins\sdk\RemoteCall\RemoteCallInterface;
@@ -35,12 +33,12 @@ class PluginSession extends SSOData
3533
const KEY_DATA = 'data';
3634

3735
/**
38-
* @var $pluginInstanceId the id of the currently used instance.
36+
* @var String $pluginInstanceId the id of the currently used instance.
3937
*/
4038
private $pluginInstanceId = null;
4139

4240
/**
43-
* @var $userView flag for userView mode.
41+
* @var boolean $userView flag for userView mode.
4442
*/
4543
private $userView = true;
4644

@@ -49,9 +47,9 @@ class PluginSession extends SSOData
4947
*
5048
* @param string $pluginId the unique name of the plugin
5149
* @param string $appSecret application public key
52-
* @param $sessionHandler optional custom session handler
53-
* @param $leeway in seconds to compensate clock skew
54-
* @param $remoteCallHandler a class handling remote calls
50+
* @param SessionHandlerInterface $sessionHandler optional custom session handler
51+
* @param int $leeway in seconds to compensate clock skew
52+
* @param RemoteCallInterface $remoteCallHandler a class handling remote calls
5553
*
5654
* @throws SSOAuthenticationException | SSOException
5755
*/

src/SSOToken.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
* PHP version 5.5.9
77
*
88
* @category Authentication
9-
* @copyright 2017-2019 Staffbase, GmbH.
9+
* @copyright 2017-2019 Staffbase, GmbH.
1010
* @author Vitaliy Ivanov
1111
* @license http://www.apache.org/licenses/LICENSE-2.0
1212
* @link https://github.com/staffbase/plugins-sdk-php
1313
*/
1414

1515
namespace Staffbase\plugins\sdk;
1616

17+
use Lcobucci\JWT\Token;
1718
use Lcobucci\JWT\Parser;
18-
use Lcobucci\JWT\Builder;
19+
use Lcobucci\JWT\Signer\Key;
1920
use Lcobucci\JWT\ValidationData;
2021
use Lcobucci\JWT\Claim\Validatable;
21-
use Lcobucci\JWT\Signer\Keychain;
2222
use Lcobucci\JWT\Signer\Rsa\Sha256;
2323
use Staffbase\plugins\sdk\Exceptions\SSOException;
2424
use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException;
@@ -29,8 +29,8 @@
2929
*/
3030
class SSOToken extends SSOData
3131
{
32-
/**
33-
* @var $token Lcobucci\JWT\Token
32+
/**
33+
* @var Token $token
3434
*/
3535
private $token = null;
3636

@@ -39,7 +39,7 @@ class SSOToken extends SSOData
3939
*
4040
* @param string $appSecret Either a PEM key or a file:// URL.
4141
* @param string $tokenData The token text.
42-
* @param int $leeway count of seconds added to current timestamp
42+
* @param int $leeway count of seconds added to current timestamp
4343
*
4444
* @throws SSOException on invalid parameters.
4545
*/
@@ -66,9 +66,7 @@ public function __construct($appSecret, $tokenData, $leeway = 0) {
6666
*
6767
* @param string $appSecret Either a PEM formatted key or a file:// URL of the same.
6868
* @param string $tokenData The token text.
69-
* @param int $leeway count of seconds added to current timestamp
70-
*
71-
* @return Lcobucci\JWT\Token;
69+
* @param int $leeway count of seconds added to current timestamp
7270
*
7371
* @throws SSOAuthenticationException if the parsing/verification/validation of the token fails.
7472
*/
@@ -79,13 +77,13 @@ protected function parseToken($appSecret, $tokenData, $leeway) {
7977

8078
// verify signature
8179
$signer = new Sha256();
82-
$keychain = new Keychain();
80+
$key = new Key($appSecret);
8381

84-
if (!$this->token->verify($signer, $keychain->getPublicKey($appSecret)))
82+
if (!$this->token->verify($signer, $key))
8583
throw new SSOAuthenticationException('Token verification failed.');
8684

8785
// validate claims
88-
$data = new ValidationData(time() +$leeway); // iat, nbf and exp are validated by default
86+
$data = new ValidationData(time(), $leeway); // iat, nbf and exp are validated by default
8987

9088
if (!$this->token->validate($data)) {
9189
$this->throwVerboseException($data);
@@ -104,7 +102,7 @@ protected function parseToken($appSecret, $tokenData, $leeway) {
104102
* @return string PEM encoded key
105103
*/
106104
public static function base64ToPEMPublicKey($data) {
107-
105+
108106
$data = strtr($data, array(
109107
"\r" => "",
110108
"\n" => ""
@@ -122,13 +120,13 @@ public static function base64ToPEMPublicKey($data) {
122120
* Due to minor shortcomings of the library we have to redo the validation
123121
* manually to get the reason for the failure and propagate it.
124122
* We emulate the validation process for the v3.x of the library.
125-
*
123+
*
126124
* This will most likely have to change on library upgrade either
127125
* by using then supported verbosity or reimplementing validation
128126
* as done in the new flow.
129-
*
130-
* @param Lcobucci\JWT\ValidationData $data to validate against
131-
*
127+
*
128+
* @param ValidationData $data to validate against
129+
*
132130
* @throws SSOAuthenticationException always.
133131
*/
134132
protected function throwVerboseException(ValidationData $data) {
@@ -193,4 +191,4 @@ protected function getAllClaims() {
193191

194192
return $res;
195193
}
196-
}
194+
}

0 commit comments

Comments
 (0)