使用 RestServer 的 Api 密钥无效

问题描述 投票:0回答:3

我正在使用 codeigniter Rest 服务器 api 库。

当我输入 http://localhost/projects/myapi/key/index_put.php 并按 Enter 键时,出现以下错误:

<xml>
<status>0</status>
<error>Invalid API Key</error>
</xml>

当我在网址中给出虚拟字符串时,例如:

http://localhost/projects/myapi/key/index_put.php?X-API-KEY=asldfj9alsdjflja97979797997

我也遇到同样的问题。有什么想法吗?

index_put.php

public function index_put() {
        // Build a new key
        $key = self::_generate_key();
        // If no key level provided, give them a rubbish one
        $level = $this->put('level') ? $this->put('level') : 1;
        $ignore_limits = $this->put('ignore_limits') ? $this->put('ignore_limits') : 1;

        // Insert the new key
        if (self::_insert_key($key, array('level' => $level, 'ignore_limits' => $ignore_limits))) {
            $this->response(array('status' => 1, 'key' => $key), 201); // 201 = Created
        } else {
            $this->response(array('status' => 0, 'error' => 'Could not save the key.'), 500); // 500 = Internal Server Error
        }
    }
php codeigniter codeigniter-restserver
3个回答
1
投票

我遇到了同样的问题。不要在 URL 中提及 put/get/post ,RestServer 本身会根据您传递的参数识别请求性质,解决您的问题所需的两个步骤。

第一步:

http://localhost/projects/myapi/key/index_put.php

必须更改为:

http://localhost/projects/myapi/key/index.php

第二步:

在键表中使用

sha1
(最多 40 个字符)创建一个 api(表结构显示在 config/rest.php 文件中), 在
is_private_key
字段中输入 1,在
ip_address
字段中输入 ::1。 创建记录,然后再次检查。


0
投票

这个问题很老了,但对于那些发现这个问题的人来说,答案是:

https://github.com/chriskacerguis/codeigniter-restserver 使用 PUT 方法时,API KEY 应以 x-www-form-urlencoded 类型位于 put 标头变量中。

使用 google chrome postman 并填写如下图所示:


0
投票

这对我有用:

在文件 application/config/rest.php 中搜索“auth_override_class_method”部分并添加以下行:

$config['auth_override_class_method']['key']['*'] = '基本';

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.