-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SS4 compat: Rename code to src, tabs to spaces, implement namespaces,…
… PSR-4 autoloader
- Loading branch information
1 parent
d308fd2
commit 93eea8d
Showing
13 changed files
with
338 additions
and
244 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# For more information about the properties used in this file, | ||
# please see the EditorConfig documentation: | ||
# http://editorconfig.org | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[{*.yml,package.json}] | ||
indent_size = 2 | ||
|
||
# The indent size used in the package.json file cannot be changed: | ||
# https://github.com/npm/npm/pull/3180#issuecomment-16336516 |
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,5 @@ | ||
mappings: | ||
ApiKeyMemberExtension: Sminnee\ApiKey\ApiKeyMemberExtension | ||
ApiKeyRequestFilter: Sminnee\ApiKey\ApiKeyRequestFilter | ||
GridFieldAddApiKeyButton: Sminnee\ApiKey\GridFieldAddApiKeyButton | ||
MemberApiKey: Sminnee\ApiKey\MemberApiKey |
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,25 +1,30 @@ | ||
SilverStripe API Key | ||
==================== | ||
# SilverStripe API Key | ||
|
||
This module provides a way of creating an managing API keys within SilverStripe. This can be useful for building RESTful | ||
and other APIs. | ||
|
||
How it works | ||
------------ | ||
## Requirements | ||
|
||
* SilverStripe ^4.0 | ||
* PHP 5.5+ | ||
|
||
## How it works | ||
|
||
* Extensions the the `SecurityAdmin` provide interfaces for seeing API keys, and generating new ones. API keys are | ||
allocated member-by-member. | ||
* A `RequestFilter` will look for an API key header (default: `X-API-Key`) and if it is present, authenticate the | ||
user so that Member::currentUser() will return the corresponding member. | ||
user so that Member::currentUser() will return the corresponding member. This should be configured by non-GraphQL | ||
requests. | ||
* A `ApiKeyAuthenticator` should be configured for [GraphQL](https://github.com/silverstripe/silverstripe-graphql) | ||
request and will return the authenticated member for GraphQL contexts to use, while not applying it to the CMS | ||
session. | ||
|
||
Limitations | ||
----------- | ||
## Limitations | ||
|
||
* You can't limit the rights that the API key has to be more granular than "all rights of the given user". | ||
* Keys can't be disabled, only deleted | ||
* No support for storing encrypted ("read-once") keys | ||
|
||
Status | ||
------ | ||
## Status | ||
|
||
This should be considered experimental for now, and used with care. It has not received a security audit. |
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,15 +1,22 @@ | ||
--- | ||
Name: apikey | ||
--- | ||
Member: | ||
SilverStripe\Security\Member: | ||
extensions: | ||
- ApiKeyMemberExtension | ||
- Sminnee\ApiKey\ApiKeyMemberExtension | ||
|
||
Injector: | ||
RequestProcessor: | ||
properties: | ||
filters: | ||
- '%$ApiKeyRequestFilter' | ||
Sminnee\ApiKeyRequestFilter: | ||
header_name: 'X-Api-Key' | ||
|
||
ApiKeyRequestFilter: | ||
header_name: 'X-Api-Key' | ||
# For regular requests, enable the RequestFilter: | ||
# SilverStripe\Core\Injector\Injector: | ||
# SilverStripe\Control\RequestProcessor: | ||
# properties: | ||
# filters: | ||
# - '%$ApiKeyRequestFilter' | ||
|
||
# For GraphQL requests, enable the ApiKeyAuthenticator: | ||
SilverStripe\GraphQL\Auth\Handler: | ||
authenticators: | ||
- class: Sminnee\ApiKey\ApiKeyAuthenticator | ||
priority: 30 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,13 +3,25 @@ | |
"description": "API Key management for SilverStripe", | ||
"type": "silverstripe-module", | ||
"require": { | ||
"silverstripe/framework": "^3.1" | ||
"silverstripe/framework": "^4.0@dev" | ||
}, | ||
"license": "BSD-3-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Sam Minnee", | ||
"email": "[email protected]" | ||
} | ||
] | ||
], | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
} | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Sminnee\\ApiKey\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace Sminnee\ApiKey; | ||
|
||
use MemberApiKey; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; | ||
use SilverStripe\Forms\GridField\GridFieldAddNewButton; | ||
use SilverStripe\Forms\GridField\GridFieldDeleteAction; | ||
use SilverStripe\Forms\GridField\GridFieldDetailForm; | ||
use SilverStripe\Forms\GridField\GridFieldEditButton; | ||
use SilverStripe\ORM\DataExtension; | ||
|
||
class ApiKeyMemberExtension extends DataExtension | ||
{ | ||
private static $has_many = [ | ||
'ApiKeys' => MemberApiKey::class, | ||
]; | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$grid = $fields->dataFieldByName('ApiKeys'); | ||
if (!$grid) { | ||
return; | ||
} | ||
|
||
$gridConfig = $grid->getConfig(); | ||
|
||
// Simplify view | ||
$gridConfig->removeComponentsByType(GridFieldAddExistingAutocompleter::class); | ||
$gridConfig->removeComponentsByType(GridFieldDetailForm::class); | ||
$gridConfig->removeComponentsByType(GridFieldEditButton::class); | ||
|
||
// Better add key button | ||
$gridConfig->removeComponentsByType(GridFieldAddNewButton::class); | ||
$gridConfig->addComponent(new GridFieldAddApiKeyButton('buttons-before-left')); | ||
|
||
// Replace unlink with a real delete | ||
$gridConfig->removeComponentsByType(GridFieldDeleteAction::class); | ||
$gridConfig->addComponent(new GridFieldDeleteAction()); | ||
} | ||
} |
Oops, something went wrong.