-
I was trying to use the Pls kindly check my configuration and function, if I was missing something. Serverless.ymlfunctions:
websocket:
handler: handlers/websocket.php
memorySize: 512
layers:
- ${bref:layer.php-80}
events:
- websocket:
route: $connect
authorizer:
name: auth
identitySource:
- 'route.request.header.Authorization'
- websocket: $disconnect
- websocket: $default
auth:
handler: handlers/auth.php
memorySize: 512
layers:
- ${bref:layer.php-80} AuthHandleruse Bref\Context\Context;
use Bref\Event\Http\HttpResponse;
use Exception;
class AuthHandler implements \Bref\Event\Handler
{
use HasBearerToken;
const ALLOW = 'Allow';
const DENY = 'Deny';
public function handle($event, Context $context)
{
$authorization = data_get($event, 'headers.Authorization');
$methodArn = data_get($event, 'methodArn');
try {
// ......
return new HttpResponse($this->generatePolicy('PRINCIPLEID', self::ALLOW, $methodArn));
}
} catch (Exception $e) {
// .....
}
return new HttpResponse($this->generatePolicy('PRINCIPLEID', self::DENY, $methodArn), [], 401);
}
/**
* @param string $principal_id
* @param string $effect Allow|Deny
* @param string $resource
*
* @return string
*/
protected function generatePolicy(string $principal_id, string $effect, string $resource): string
{
return json_encode([
'principalId' => $principal_id,
'policyDocument' => [
'Version' => '2012-10-17',
'Statement' => [
[
'Action' => 'execute-api:Invoke',
'Effect' => $effect,
'Resource' => $resource
]
]
]
]);
}
}
|
Beta Was this translation helpful? Give feedback.
Answered by
semsphy
Sep 23, 2021
Replies: 1 comment
-
I did it now. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
semsphy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did it now.