Skip to content

Instantly share code, notes, and snippets.

@vrajroham
Last active April 5, 2019 08:39
Show Gist options
  • Save vrajroham/e02450ad32e4fda6a3d5896ed3757119 to your computer and use it in GitHub Desktop.
Save vrajroham/e02450ad32e4fda6a3d5896ed3757119 to your computer and use it in GitHub Desktop.
trait AlexaAuthorization{
public function parseToken($token)
{
$key_path = Passport::keyPath('oauth-public.key');
$this->parseTokenKey = file_get_contents($key_path);
$token = (new Parser())->parse((string) $token);
$signer = new Sha256();
if ($token->verify($signer, $this->parseTokenKey)) {
$userId = $token->getClaim('sub');
return $userId;
} else {
return false;
}
}
}
if (Alexa::slot('what') != null) {
// Perform operations
}else{
if (array_get(Alexa::request(), 'request.dialogState') == 'STARTED' || array_get(Alexa::request(), 'request.dialogState') == 'IN_PROGRESS') {
return (new AlexaResponse())->endSession(false)->withDirective(new Delegate());
}
return Alexa::say("I didn't understand what you said")->endSession(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment