-
Notifications
You must be signed in to change notification settings - Fork 24
Silverstripe 5 compatibility #37
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
anhld
wants to merge
10
commits into
Firesphere:master
Choose a base branch
from
anhld:updates/silverstripe-5
base: master
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d17e405
Update graphql constraint
e576810
First cut of GraphQL 4 compatibility
6f40245
Silverstripe 5 compatibility.
anhld 5633a5a
Put silverstripe/graphql back.
anhld af890e3
Validate key input. Update argument.
anhld 11b5286
Fix bad format error if giving a negative value.
anhld 9b906c1
Update tests.
anhld 859904a
Bug fixing.
anhld f47ecd2
Disallow creating token with a blank password. See https://tinyurl.co…
anhld c00f882
Update tests and docs for anonymous user.
anhld 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| Name: jwt-session-manager-middleware | ||
| After: '#session-manager-middleware' | ||
| Only: | ||
| moduleexists: | ||
| - 'silverstripe/session-manager' | ||
| --- | ||
| SilverStripe\Core\Injector\Injector: | ||
| SilverStripe\Control\Director: | ||
| properties: | ||
| Middlewares: | ||
| LoginSessionMiddleware: '%$Firesphere\GraphQLJWT\Middleware\JWTLoginSessionMiddleware' |
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| resolvers: | ||
| - Firesphere\GraphQLJWT\Resolvers\Resolver |
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| TokenStatus: | ||
| values: | ||
| OK: | ||
| value: OK | ||
| description: JWT token is valid | ||
| INVALID: | ||
| value: INVALID | ||
| description: JWT token is valid | ||
| EXPIRED: | ||
| value: EXPIRED | ||
| description: JWT token has expired, but can be renewed | ||
| DEAD: | ||
| value: DEAD | ||
| description: JWT token has expired and cannot be renewed | ||
| BAD_LOGIN: | ||
| value: BAD_LOGIN | ||
| description: JWT token could not be created due to invalid login credentials |
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| SilverStripe\Security\Member: | ||
| fields: | ||
| id: true | ||
| firstName: true | ||
| surname: true | ||
| email: true |
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| refreshToken: | ||
| type: MemberToken | ||
| description: Refreshes a JWT token for a valid user. | ||
| 'createToken(email: String!, password: String!)': | ||
| type: MemberToken | ||
| description: Creates a JWT token for a valid user |
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| validateToken: | ||
| description: Validates a given token from the Bearer header | ||
| type: MemberToken |
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| MemberToken: | ||
| fields: | ||
| valid: Boolean | ||
| member: | ||
| model: SilverStripe\Security\Member | ||
| token: String | ||
| status: TokenStatus | ||
| code: Int | ||
| message: String |
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
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace Firesphere\GraphQLJWT\Authentication; | ||
|
|
||
|
|
||
| use Firesphere\GraphQLJWT\Mutations\CreateTokenMutationCreator; | ||
| use SilverStripe\Core\Injector\Injectable; | ||
| use SilverStripe\Security\Authenticator; | ||
|
|
||
| class CustomAuthenticatorRegistry | ||
| { | ||
| use Injectable; | ||
|
|
||
| /** | ||
| * Extra authenticators to use for logging in with username / password | ||
| * | ||
| * @var Authenticator[] | ||
| */ | ||
| protected $customAuthenticators = []; | ||
|
|
||
| /** | ||
| * @return Authenticator[] | ||
| */ | ||
| public function getCustomAuthenticators(): array | ||
| { | ||
| return $this->customAuthenticators; | ||
| } | ||
|
|
||
| /** | ||
| * @param Authenticator[] $authenticators | ||
| * @return $this | ||
| */ | ||
| public function setCustomAuthenticators(array $authenticators): self | ||
| { | ||
| $this->customAuthenticators = $authenticators; | ||
| return $this; | ||
| } | ||
|
|
||
| } | ||
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 |
|---|---|---|
|
|
@@ -6,10 +6,10 @@ | |
| use Exception; | ||
| use Firesphere\GraphQLJWT\Extensions\MemberExtension; | ||
| use Firesphere\GraphQLJWT\Helpers\HeaderExtractor; | ||
| use Firesphere\GraphQLJWT\Helpers\RequiresAuthenticator; | ||
| use OutOfBoundsException; | ||
| use SilverStripe\Control\HTTPRequest; | ||
| use SilverStripe\Core\Injector\Injectable; | ||
| use SilverStripe\Core\Injector\Injector; | ||
| use SilverStripe\Security\AuthenticationHandler; | ||
| use SilverStripe\Security\Member; | ||
| use SilverStripe\Security\Security; | ||
|
|
@@ -22,7 +22,6 @@ | |
| class JWTAuthenticationHandler implements AuthenticationHandler | ||
| { | ||
| use HeaderExtractor; | ||
| use RequiresAuthenticator; | ||
| use Injectable; | ||
|
|
||
| /** | ||
|
|
@@ -41,8 +40,7 @@ public function authenticateRequest(HTTPRequest $request): ?Member | |
| } | ||
|
|
||
| // Validate the token. This is critical for security | ||
| $member = $this | ||
| ->getJWTAuthenticator() | ||
| $member = Injector::inst()->get(JWTAuthenticator::class) | ||
| ->authenticate(['token' => $token], $request); | ||
|
|
||
| if ($member) { | ||
|
|
@@ -70,14 +68,7 @@ public function logIn(Member $member, $persistent = false, HTTPRequest $request | |
| */ | ||
| public function logOut(HTTPRequest $request = null): void | ||
| { | ||
| // A token can actually not be invalidated, but let's flush all valid tokens from the DB. | ||
| // Note that log-out acts as a global logout (all devices) | ||
| /** @var Member|MemberExtension $member */ | ||
| $member = Security::getCurrentUser(); | ||
| if ($member) { | ||
| $member->destroyAuthTokens(); | ||
| } | ||
|
|
||
| Security::setCurrentUser(null); | ||
| // We don't take any action here. | ||
|
Owner
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. Then the token stays valid, which is even worse than logging out from everywhere... |
||
| // If we delete all tokens in this section, when a user logs out using a web interface (i.e. CMS), all the tokens will become invalid. | ||
| } | ||
| } | ||
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.
The name "CustomAuthenticatorRegistry" is too generic, a more descriptive and/or concise naming