-
Notifications
You must be signed in to change notification settings - Fork 48
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
Inconsistent Authentication Behaviour #104
Comments
Modifying
|
Related and fixable at the same time is the following (un-modified code): This is OK:
This is not:
It gets worse: This is OK:
This is not:
|
So I have also bumped into this issue. It appears I was able to circumvent this issue by creating my own separate version of use SilverStripe\Security\Permission;
use SilverStripe\RestfulServer\RestfulServer;
use SilverStripe\Security\PermissionProvider;
class CustomRestfulServer extends RestfulServer implements PermissionProvider
{
private static $endpoint_get_permissions = [
MyDataObject::class => ['API_VIEW_OBJECTS']
];
protected function getHandler($className, $id, $relationName)
{
$global_permissions = $this->config()->endpoint_get_permissions;
$member = $this->getMember();
// If permissions required and member not logged in, fail
if (empty($member) && array_key_exists($className, $global_permissions)) {
return $this->permissionFailure();
}
$result = Permission::checkMember(
$member,
$global_permissions[$className]
);
if ($result === false) {
return $this->permissionFailure();
}
return parent::getHandler($className, $id, $relationName);
}
public function providePermissions()
{
return [
"API_VIEW_OBJECTS => [
'name' => 'API View All Objects
'category' => 'API',
]
];
}
} Then, in my ---
Name: approutes
After: '#restfulserverroutes'
---
SilverStripe\Control\Director:
rules:
'api/v1': 'CustomRestfulServer' It might be quite useful if the endpoints themselves could have specific permissions mapped to them (Similar to how I believe If not though, the solution above seems to work quite well for me... |
Silverstripe 4.11 / PHP 7.4 / Module 2.5.0
Having configured the module to return a Basic Auth prompt by manipulating
Page::canView()
appropriately, I have observed inconsistencies with this module's behaviour:Observed Behaviour
Scenario #1: When accessing a specific resource such as
api/v1/page/1
and being not logged-in via Basic Auth, I am prompted for username and password.Scenario #2: When accessing a generic resource for a collection of pages such as
/api/v1/page/?start=10&limit=100
and being not logged-in via Basic Auth, I simply see{"totalSize":0,"items":[]}
with an HTTP 200.Expected Behaviour
Scenario #1: As above
Scenario #2: I should either be prompted to login or see the above JSON snippet with an HTTP 401, not 200.
The text was updated successfully, but these errors were encountered: