public function token()
    {
        $user = $this->Auth->identify();
        if (!$user) {
            throw new UnauthorizedException('Invalid username or password');
        }

        $token = [
            'id' => $user['id'],
            'exp' => time() + 60 * 60 * 24 * 7
        ];

        $this->set([
            'success' => true,
            'data' => ['token' => JWT::encode($token, Security::salt())],
            '_serialize' => ['success', 'data']
        ]);
    }