-
-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve user from the dynamic userProvider Catch possible encode/decode failure exceptions (better after #162) Handle token extractors configuration Split configuration for readability Require browser-kit for tests Refactor functional tests structure Add more functional tests Depreciate current system classes Tests subscribing to authentication events Update CHANGELOG according to these changes Document config-related changes in UPGRADE.md Deprecate JWTManagerInterface in favor of JWTTokenManagerInterface Improve functional tests by adding CallableEventSubscriber Avoid calling onAuthenticationFailure() from start() Grammar Scrutinizer fixes
- Loading branch information
Showing
41 changed files
with
1,410 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception; | ||
|
||
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
|
||
/** | ||
* Exception to be used during a failed JWT authentication process. | ||
* | ||
* @author Robin Chalas <robin.chalas@gmail.com> | ||
*/ | ||
class JWTAuthenticationException extends AuthenticationException | ||
{ | ||
/** | ||
* Returns an AuthenticationException in case of invalid token. | ||
* | ||
* To be used if the token cannot be properly decoded. | ||
* | ||
* @param JWTDecodeFailureException|null $previous | ||
* | ||
* @return JWTAuthenticationException | ||
*/ | ||
public static function invalidToken(JWTDecodeFailureException $previous = null) | ||
{ | ||
return new self($previous ? $previous->getMessage() : 'Invalid JWT Token', 0, $previous); | ||
} | ||
|
||
/** | ||
* Returns an AuthenticationException in case of token not found. | ||
* | ||
* @param string $message | ||
* | ||
* @return JWTAuthenticationException | ||
*/ | ||
public static function tokenNotFound($message = 'JWT Token not found') | ||
{ | ||
return new self($message); | ||
} | ||
|
||
/** | ||
* Returns an AuthenticationException in case of invalid user. | ||
* | ||
* To be used if no user can be loaded from the identity retrieved from | ||
* the decoded token's payload. | ||
* | ||
* @param string $identity | ||
* @param string $identityField | ||
* | ||
* @return JWTAuthenticationException | ||
*/ | ||
public static function invalidUser($identity, $identityField) | ||
{ | ||
return new self(sprintf('Unable to load a valid user with property "%s" = "%s". If the user identity has been changed, you must renew the token. Otherwise, verify that the "lexik_jwt_authentication.user_identity_field" config option is correctly set.', $identityField, $identity)); | ||
} | ||
|
||
/** | ||
* Returns an AuthenticationException in case of invalid payload. | ||
* | ||
* To be used if a key in missing in the payload or contains an unexpected value. | ||
* | ||
* @param string $message | ||
* | ||
* @return JWTAuthenticationException | ||
*/ | ||
public static function invalidPayload($message = 'Invalid payload') | ||
{ | ||
return new self($message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Security/Authentication/Token/PreAuthenticationJWTUserToken.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Security\Authentication\Token; | ||
|
||
use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken; | ||
|
||
/** | ||
* PreAuthenticationJWTUserToken. | ||
* | ||
* @author Robin Chalas <robin.chalas@gmail.com> | ||
*/ | ||
final class PreAuthenticationJWTUserToken extends PreAuthenticationGuardToken | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $rawToken; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $payload; | ||
|
||
/** | ||
* @param string $rawToken | ||
*/ | ||
public function __construct($rawToken) | ||
{ | ||
$this->rawToken = $rawToken; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCredentials() | ||
{ | ||
return $this->rawToken; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setPayload(array $payload) | ||
{ | ||
$this->payload = $payload; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getPayload() | ||
{ | ||
return $this->payload; | ||
} | ||
} |
Oops, something went wrong.