public function generateToken($ttl = 3600) {
        $payload = array_merge($this->customClaims, array(
            'scope' => array(),
            'iss' => $this->accountSid,
            'exp' => time() + $ttl,
        ));
        $scopeStrings = array();

        foreach ($this->scopes as $scope) {
            if ($scope->privilege == "outgoing" && $this->clientName)
                $scope->params["clientName"] = $this->clientName;
            $scopeStrings[] = $scope->toString();
        }

        $payload['scope'] = implode(' ', $scopeStrings);
        return JWT::encode($payload, $this->authToken, 'HS256');
    }