Merge pull request #1473 from jonnybarnes/1455-scope-verification-is-failing-for-micropub-requests
Improve scope checking
This commit is contained in:
commit
d6a0b1dcf6
3 changed files with 28 additions and 8 deletions
|
@ -67,7 +67,12 @@ class MicropubController extends Controller
|
|||
$this->logMicropubRequest($request->all());
|
||||
|
||||
if (($request->input('h') === 'entry') || ($request->input('type.0') === 'h-entry')) {
|
||||
if (stripos($tokenData->claims()->get('scope'), 'create') === false) {
|
||||
$scopes = $tokenData->claims()->get('scope');
|
||||
if (is_string($scopes)) {
|
||||
$scopes = explode(' ', $scopes);
|
||||
}
|
||||
|
||||
if (! in_array('create', $scopes)) {
|
||||
$micropubResponses = new MicropubResponses();
|
||||
|
||||
return $micropubResponses->insufficientScopeResponse();
|
||||
|
@ -81,7 +86,11 @@ class MicropubController extends Controller
|
|||
}
|
||||
|
||||
if ($request->input('h') === 'card' || $request->input('type.0') === 'h-card') {
|
||||
if (stripos($tokenData->claims()->get('scope'), 'create') === false) {
|
||||
$scopes = $tokenData->claims()->get('scope');
|
||||
if (is_string($scopes)) {
|
||||
$scopes = explode(' ', $scopes);
|
||||
}
|
||||
if (! in_array('create', $scopes)) {
|
||||
$micropubResponses = new MicropubResponses();
|
||||
|
||||
return $micropubResponses->insufficientScopeResponse();
|
||||
|
@ -95,7 +104,11 @@ class MicropubController extends Controller
|
|||
}
|
||||
|
||||
if ($request->input('action') === 'update') {
|
||||
if (stripos($tokenData->claims()->get('scope'), 'update') === false) {
|
||||
$scopes = $tokenData->claims()->get('scope');
|
||||
if (is_string($scopes)) {
|
||||
$scopes = explode(' ', $scopes);
|
||||
}
|
||||
if (! in_array('update', $scopes)) {
|
||||
$micropubResponses = new MicropubResponses();
|
||||
|
||||
return $micropubResponses->insufficientScopeResponse();
|
||||
|
|
|
@ -17,7 +17,6 @@ use Illuminate\Http\Response;
|
|||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lcobucci\JWT\Token\InvalidTokenStructure;
|
||||
use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
|
||||
|
@ -51,7 +50,11 @@ class MicropubMediaController extends Controller
|
|||
return $micropubResponses->tokenHasNoScopeResponse();
|
||||
}
|
||||
|
||||
if (Str::contains($tokenData->claims()->get('scope'), 'create') === false) {
|
||||
$scopes = $tokenData->claims()->get('scope');
|
||||
if (is_string($scopes)) {
|
||||
$scopes = explode(' ', $scopes);
|
||||
}
|
||||
if (! in_array('create', $scopes)) {
|
||||
$micropubResponses = new MicropubResponses();
|
||||
|
||||
return $micropubResponses->insufficientScopeResponse();
|
||||
|
@ -119,7 +122,11 @@ class MicropubMediaController extends Controller
|
|||
return $micropubResponses->tokenHasNoScopeResponse();
|
||||
}
|
||||
|
||||
if (Str::contains($tokenData->claims()->get('scope'), 'create') === false) {
|
||||
$scopes = $tokenData->claims()->get('scope');
|
||||
if (is_string($scopes)) {
|
||||
$scopes = explode(' ', $scopes);
|
||||
}
|
||||
if (! in_array('create', $scopes)) {
|
||||
$micropubResponses = new MicropubResponses();
|
||||
|
||||
return $micropubResponses->insufficientScopeResponse();
|
||||
|
|
|
@ -14,8 +14,8 @@ trait TestToken
|
|||
return $config->builder()
|
||||
->issuedAt(new DateTimeImmutable())
|
||||
->withClaim('client_id', 'https://quill.p3k.io')
|
||||
->withClaim('me', 'https://jonnybarnes.localhost')
|
||||
->withClaim('scope', 'create update')
|
||||
->withClaim('me', 'http://jonnybarnes.localhost')
|
||||
->withClaim('scope', ['create', 'update'])
|
||||
->getToken($config->signer(), $config->signingKey())
|
||||
->toString();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue