1919abstract class AbstractToken
2020{
2121
22- /**
23- * @var Token $token
24- */
2522 private Token $ token ;
2623
27- /**
28- * @var Key $signerKey
29- */
3024 private Key $ signerKey ;
3125
32- /**
33- * @var Configuration $config
34- */
3526 private Configuration $ config ;
3627
28+ private array $ constraints ;
29+
3730 /**
3831 * Constructor
3932 *
@@ -45,7 +38,7 @@ abstract class AbstractToken
4538 * @throws SSOAuthenticationException
4639 * @throws SSOException on invalid parameters.
4740 */
48- public function __construct (string $ appSecret , string $ tokenData , Signer $ signer , array $ constrains = [])
41+ public function __construct (string $ appSecret , protected string $ tokenData , Signer $ signer , array $ constrains = [])
4942 {
5043 if (!trim ($ appSecret )) {
5144 throw new SSOException ('Parameter appSecret for SSOToken is empty. ' );
@@ -58,28 +51,31 @@ public function __construct(string $appSecret, string $tokenData, Signer $signer
5851 $ this ->setSignerKey (trim ($ appSecret ));
5952 $ this ->setConfig (Configuration::forSymmetricSigner ($ signer , $ this ->getSignerKey ()));
6053
61- $ defaultConstrains = [
54+ $ this -> constraints = [
6255 new SignedWith ($ signer , $ this ->getSignerKey ()),
56+ ...$ constrains ,
6357 ];
64-
65- $ this ->parseToken ($ tokenData , array_merge ($ defaultConstrains , $ constrains ));
6658 }
6759
6860 /**
6961 * Creates and validates an SSO token.
7062 *
71- * @param string $tokenData The token text.
72- * @param Constraint[] $constrains an array of validation instances
73- *
74- * @throws SSOAuthenticationException if the parsing/verification/validation of the token fails.
7563 */
76- protected function parseToken (string $ tokenData , array $ constrains = [] ): void
64+ protected function parseToken (): void
7765 {
7866 // parse text
79- $ this ->token = $ this ->config ->parser ()->parse ($ tokenData );
67+ $ this ->token = $ this ->config ->parser ()->parse ($ this ->tokenData );
68+ }
8069
70+ /**
71+ * Creates and validates an SSO token.
72+ *
73+ * @throws SSOAuthenticationException if the parsing/verification/validation of the token fails.
74+ */
75+ protected function validateToken (): void
76+ {
8177 try {
82- $ this ->config ->validator ()->assert ($ this ->token , ...$ constrains );
78+ $ this ->config ->validator ()->assert ($ this ->token , ...$ this -> constraints );
8379 } catch (RequiredConstraintsViolated $ violation ) {
8480 throw new SSOAuthenticationException ($ violation ->getMessage ());
8581 }
@@ -89,8 +85,6 @@ protected function parseToken(string $tokenData, array $constrains = []): void
8985 * Test if a claim is set.
9086 *
9187 * @param string $claim name.
92- *
93- * @return boolean
9488 */
9589 protected function hasClaim (string $ claim ): bool
9690 {
@@ -111,8 +105,6 @@ protected function getClaim(string $claim)
111105
112106 /**
113107 * Get an array of all available claims and their values.
114- *
115- * @return array
116108 */
117109 protected function getAllClaims (): array
118110 {
@@ -136,16 +128,15 @@ public static function base64ToPEMPublicKey(string $data): string
136128 ));
137129
138130 return
139- "-----BEGIN PUBLIC KEY----- \n" .
140- chunk_split ($ data , 64 ).
131+ "-----BEGIN PUBLIC KEY----- \n" .
132+ chunk_split ($ data , 64 ) .
141133 "-----END PUBLIC KEY----- \n" ;
142134 }
143135
144136 /**
145137 * Set the configuration
146138 *
147139 * @param Configuration $value
148- * @return void
149140 */
150141 public function setConfig (Configuration $ value ): void
151142 {
@@ -154,17 +145,15 @@ public function setConfig(Configuration $value): void
154145
155146 /**
156147 * Get the configuration
157- * @return Configuration
158148 */
159- public function getConfig ():Configuration
149+ public function getConfig (): Configuration
160150 {
161151 return $ this ->config ;
162152 }
163153
164154 /**
165155 * Creates a key from the secret and stores it to the property
166156 * @param string $secret
167- * @return void
168157 */
169158 public function setSignerKey (string $ secret ): void
170159 {
@@ -173,7 +162,6 @@ public function setSignerKey(string $secret): void
173162
174163 /**
175164 * Get the Signer key
176- * @return Key
177165 */
178166 public function getSignerKey (): Key
179167 {
@@ -184,7 +172,6 @@ public function getSignerKey(): Key
184172 * Decides between the new key methods, the JWT library offers
185173 *
186174 * @param string $appSecret
187- * @return Key
188175 */
189176 private function getKey (string $ appSecret ): Key
190177 {
0 commit comments