forked from luciferous/jwt
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add code for each Exception #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicumicle
wants to merge
23
commits into
firebase:main
Choose a base branch
from
nicumicle:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+284
−64
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
45cb0f4
Add error codes to all exceptions
nicumicle da07b36
Refactor Exception codes
nicumicle 6d41ab7
Add newline at end of file
nicumicle a2d3bb7
Add public to const in BeforeValidException
nicumicle bf7d6db
Fix exception codes
nicumicle abf93d1
Move all exception codes to the ExceptionCodes class
nicumicle 1b9d33a
Add error codes to all exceptions
nicumicle 6451f85
Refactor Exception codes
nicumicle 33b5104
Add newline at end of file
nicumicle 2f467b3
Add public to const in BeforeValidException
nicumicle 38b5fe6
Fix exception codes
nicumicle 11271dc
Move all exception codes to the ExceptionCodes class
nicumicle 47a3afd
Merging main
nicumicle 8a85356
Merge branch 'main' into main
bshaffer 750ceb8
Merge branch 'main' into main
bshaffer ff1f054
Update src/JWT.php
bshaffer b0aa2d5
Merge branch 'main' into main
nicumicle 2e50332
add exception codes
nicumicle b7fc2ef
Change exception codes class to an interface
nicumicle c90277a
Merge branch 'firebase:main' into main
nicumicle 8d8b372
Fix tests
nicumicle 7528abe
fix tests
nicumicle 1823840
Merge branch 'main' into main
bshaffer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -101,7 +101,10 @@ public function __construct( | |
public function offsetGet($keyId): Key | ||
{ | ||
if (!$this->keyIdExists($keyId)) { | ||
throw new OutOfBoundsException('Key ID not found'); | ||
throw new OutOfBoundsException( | ||
'Key ID not found', | ||
JwtExceptionInterface::KEY_ID_NOT_FOUND | ||
); | ||
} | ||
return JWK::parseKey($this->keySet[$keyId], $this->defaultAlg); | ||
} | ||
|
@@ -121,15 +124,21 @@ public function offsetExists($keyId): bool | |
*/ | ||
public function offsetSet($offset, $value): void | ||
{ | ||
throw new LogicException('Method not implemented'); | ||
throw new LogicException( | ||
'Method not implemented', | ||
JwtExceptionInterface::OFFSET_SET_METHOD_NOT_IMPLEMENTED | ||
); | ||
} | ||
|
||
/** | ||
* @param string $offset | ||
*/ | ||
public function offsetUnset($offset): void | ||
{ | ||
throw new LogicException('Method not implemented'); | ||
throw new LogicException( | ||
'Method not implemented', | ||
JwtExceptionInterface::OFFSET_UNSET_METHOD_NOT_IMPLEMENTED | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -140,11 +149,11 @@ private function formatJwksForCache(string $jwks): array | |
$jwks = json_decode($jwks, true); | ||
|
||
if (!isset($jwks['keys'])) { | ||
throw new UnexpectedValueException('"keys" member must exist in the JWK Set'); | ||
throw new UnexpectedValueException('"keys" member must exist in the JWK Set', JwtExceptionInterface::CACHED_KEY_MISSING); | ||
} | ||
|
||
if (empty($jwks['keys'])) { | ||
throw new InvalidArgumentException('JWK Set did not contain any keys'); | ||
throw new InvalidArgumentException('JWK Set did not contain any keys', JwtExceptionInterface::CACHED_KEY_EMPTY); | ||
} | ||
|
||
$keys = []; | ||
|
@@ -185,7 +194,7 @@ private function keyIdExists(string $keyId): bool | |
$jwksResponse->getReasonPhrase(), | ||
$this->jwksUri, | ||
), | ||
$jwksResponse->getStatusCode() | ||
JwtExceptionInterface::CACHED_KEY_GET_JWK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change! |
||
); | ||
} | ||
$this->keySet = $this->formatJwksForCache((string) $jwksResponse->getBody()); | ||
|
@@ -243,7 +252,10 @@ private function getCacheItem(): CacheItemInterface | |
private function setCacheKeys(): void | ||
{ | ||
if (empty($this->jwksUri)) { | ||
throw new RuntimeException('JWKS URI is empty'); | ||
throw new RuntimeException( | ||
'JWKS URI is empty', | ||
JwtExceptionInterface::JWKS_URI_IS_EMPTY | ||
); | ||
} | ||
|
||
// ensure we do not have illegal characters | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could clean this up quite a bit by making
JWTExceptionWithPayloadInterface
extendJwtExceptioninterface
.