-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from tractorcow/pulls/pull-back-work
Major upgrade: Changes documented
- Loading branch information
Showing
30 changed files
with
1,240 additions
and
561 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# For more information about the properties used in | ||
# this file, please see the EditorConfig documentation: | ||
# http://editorconfig.org/ | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.yml] | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[*.{yml,json}] | ||
indent_size = 2 | ||
|
||
[composer.json] | ||
indent_size = 4 |
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,7 @@ | ||
--- | ||
Name: firesphere-jwt-anonymous | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
SilverStripe\Security\Member.anonymous: | ||
class: SilverStripe\Security\Member | ||
factory: Firesphere\GraphQLJWT\Authentication\AnonymousUserFactory |
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 |
---|---|---|
@@ -1,32 +1,20 @@ | ||
--- | ||
after: graphqlconfig | ||
Name: firesphere-jwt-injections | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
SilverStripe\Security\AuthenticationHandler: | ||
properties: | ||
Handlers: | ||
jwt: %$Firesphere\GraphQLJWT\Authentication\JWTAuthenticationHandler | ||
jwt: %$Firesphere\GraphQLJWT\Authentication\JWTAuthenticationHandler | ||
Firesphere\GraphQLJWT\Authentication\JWTAuthenticationHandler: | ||
properties: | ||
Authenticator: %$Firesphere\GraphQLJWT\Authentication\JWTAuthenticator | ||
--- | ||
after: graphqlroutes | ||
--- | ||
SilverStripe\Control\Director: | ||
rules: | ||
graphql: | ||
Controller: 'SilverStripe\GraphQL\Controller' | ||
# @internal - Experimental config | ||
# @todo - move this to a per-schema configuration, and simply register the named schema for this endpoint | ||
# https://github.com/silverstripe/silverstripe-graphql/issues/52 | ||
Stage: Live | ||
Permissions: false | ||
--- | ||
name: graphqljwt | ||
after: | ||
- '#coresecurity' | ||
--- | ||
Firesphere\GraphQLJWT\Authentication\JWTAuthenticator: | ||
nbf_time: 0 | ||
nbf_expiration: 3600 | ||
anonymous_allowed: false | ||
JWTAuthenticator: %$Firesphere\GraphQLJWT\Authentication\JWTAuthenticator | ||
Firesphere\GraphQLJWT\Mutations\CreateTokenMutationCreator: | ||
properties: | ||
JWTAuthenticator: %$Firesphere\GraphQLJWT\Authentication\JWTAuthenticator | ||
Firesphere\GraphQLJWT\Mutations\RefreshTokenMutationCreator: | ||
properties: | ||
JWTAuthenticator: %$Firesphere\GraphQLJWT\Authentication\JWTAuthenticator | ||
Firesphere\GraphQLJWT\Queries\ValidateTokenQueryCreator: | ||
properties: | ||
JWTAuthenticator: %$Firesphere\GraphQLJWT\Authentication\JWTAuthenticator |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,39 +1,35 @@ | ||
{ | ||
"name": "firesphere/graphql-jwt", | ||
"description": "JWT Authentication for GraphQL", | ||
"type": "silverstripe-vendormodule", | ||
"license": "bsd-3-clause", | ||
"require": { | ||
"php": ">=5.6", | ||
"silverstripe/recipe-core": "^4.0", | ||
"silverstripe/versioned": "^1.0", | ||
"silverstripe/graphql": "^3.0", | ||
"lcobucci/jwt": "^3.2" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^2.4", | ||
"phpunit/PHPUnit": "^5.7", | ||
"scriptfusion/phpunit-immediate-exception-printer": "^1" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
"name": "firesphere/graphql-jwt", | ||
"description": "JWT Authentication for GraphQL", | ||
"type": "silverstripe-vendormodule", | ||
"license": "bsd-3-clause", | ||
"require": { | ||
"php": ">=7.1", | ||
"silverstripe/framework": "^4.3", | ||
"silverstripe/graphql": "^3.0", | ||
"lcobucci/jwt": "^3.2", | ||
"ext-json": "*" | ||
}, | ||
"installer-name": "graphql-jwt" | ||
}, | ||
"config": { | ||
"process-timeout": 600 | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Firesphere\\GraphQLJWT\\Authentication\\": "src/Authentication", | ||
"Firesphere\\GraphQLJWT\\Extensions\\": "src/Extensions", | ||
"Firesphere\\GraphQLJWT\\Helpers\\": "src/Helpers", | ||
"Firesphere\\GraphQLJWT\\Mutations\\": "src/Mutations", | ||
"Firesphere\\GraphQLJWT\\Queries\\": "src/Queries", | ||
"Firesphere\\GraphQLJWT\\Types\\": "src/Types" | ||
} | ||
}, | ||
"prefer-stable": true, | ||
"minimum-stability": "dev" | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^2.4", | ||
"phpunit/phpunit": "^5.7", | ||
"scriptfusion/phpunit-immediate-exception-printer": "^1" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "2.x-dev" | ||
}, | ||
"installer-name": "graphql-jwt" | ||
}, | ||
"config": { | ||
"process-timeout": 600 | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Firesphere\\GraphQLJWT\\": "src/", | ||
"Firesphere\\GraphQLJWT\\Tests\\": "tests/unit/" | ||
} | ||
}, | ||
"prefer-stable": true, | ||
"minimum-stability": "dev" | ||
} |
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,76 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Firesphere\GraphQLJWT\Authentication; | ||
|
||
use BadMethodCallException; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Core\Config\Configurable; | ||
use SilverStripe\Core\Injector\Injectable; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\ORM\ValidationResult; | ||
use SilverStripe\Security\Authenticator; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator; | ||
|
||
class AnonymousUserAuthenticator extends MemberAuthenticator | ||
{ | ||
use Configurable; | ||
use Injectable; | ||
|
||
/** | ||
* Anonymous username | ||
* | ||
* @var string | ||
*/ | ||
private static $anonymous_username = 'anonymous'; | ||
|
||
public function supportedServices(): int | ||
{ | ||
return Authenticator::LOGIN | Authenticator::LOGOUT; | ||
} | ||
|
||
public function authenticate(array $data, HTTPRequest $request, ValidationResult &$result = null): ?Member | ||
{ | ||
// Only applies to request for anonymous user specifically | ||
$email = $data['Email'] ?? null; | ||
if ($email !== static::config()->get('anonymous_username')) { | ||
return null; | ||
} | ||
|
||
return parent::authenticate($data, $request, $result); | ||
} | ||
|
||
/** | ||
* Attempt to find and authenticate member if possible from the given data | ||
* | ||
* @skipUpgrade | ||
* @param array $data Form submitted data | ||
* @param ValidationResult $result | ||
* @param Member $member This third parameter is used in the CMSAuthenticator(s) | ||
* @return Member Found member, regardless of successful login | ||
*/ | ||
protected function authenticateMember($data, ValidationResult &$result = null, Member $member = null): Member | ||
{ | ||
// Get user, or create if not exists | ||
$username = static::config()->get('anonymous_username'); | ||
$member = Injector::inst()->get(Member::class . '.anonymous', true, ['username' => $username]); | ||
|
||
// Validate this member is still allowed to login | ||
$result = $result ?: ValidationResult::create(); | ||
$member->validateCanLogin($result); | ||
|
||
// Emit failure to member and form (if available) | ||
if ($result->isValid()) { | ||
$member->registerSuccessfulLogin(); | ||
} else { | ||
$member->registerFailedLogin(); | ||
} | ||
|
||
return $member; | ||
} | ||
|
||
public function checkPassword(Member $member, $password, ValidationResult &$result = null) | ||
{ | ||
throw new BadMethodCallException("checkPassword not supported for anonymous users"); | ||
} | ||
} |
Oops, something went wrong.