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
1515namespace Staffbase \plugins \sdk ;
1616
17+ use Lcobucci \JWT \Token ;
1718use Lcobucci \JWT \Parser ;
18- use Lcobucci \JWT \Builder ;
19+ use Lcobucci \JWT \Signer \ Key ;
1920use Lcobucci \JWT \ValidationData ;
2021use Lcobucci \JWT \Claim \Validatable ;
21- use Lcobucci \JWT \Signer \Keychain ;
2222use Lcobucci \JWT \Signer \Rsa \Sha256 ;
2323use Staffbase \plugins \sdk \Exceptions \SSOException ;
2424use Staffbase \plugins \sdk \Exceptions \SSOAuthenticationException ;
2929 */
3030class 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