如何在Codeigniter中的我自己的控制器中生成API密钥 [英] How can I generate an API Key in My own Controller in Codeigniter

查看:120
本文介绍了如何在Codeigniter中的我自己的控制器中生成API密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想提到我真的是一个新手在API开发(概念,结构,最佳实践)我不太熟悉它,所以请原谅我可耻的愚蠢的问题,如果你发现它是, m使用Phil Sturgeon的REST API服务器,Curl库和REST API客户端这里是我的代码:



在我的控制器应用程序/ controllers / make_key

  function index(){
$ this-> load-> library('rest');
$ this-> load-> library('curl');
$ this-> rest-> put('https://www.myapplication.com/apifolder/key/X-API-KEY/FOO');
}

完全没有回应


$ b b

其中apifolder / key是我的key.php的位置(来自Phil Sturgeon的默认示例):



注意,我也通过地址栏:



https://www.myapplication.com/apifolder/key/X-API-KEY/FOO
- 返回({status:false,error:API密钥无效。} )



https ://www.myapplication.com/apifolder/key?X-API-KEY = FOO
- 返回({status:false,error:未知方法。 / p>

并尝试了更多的查询,但没有一个似乎工作,我唯一的问题是...



如何使这个key.php工作?

解决方案

查看我自己接受的答案在我自己的qeuestion ... Phil的文档不提供此信息。我不得不自己挖掘图书馆。


我结束了发现403禁止是因为我没有提供一个api键来生成键。

在Phil的文档中没有说明需要现有的api键才能生成键。
我在db的表中简单地创建了一个bogus键并调用 / key / index?X-API-KEY = boguskey


CodeIgniter REST API库Ajax PUT throwing 403 Forbidden

a>


Just want to mention that I am really a newbie in API development (concepts, structure, best practices) I am not nearly familiar with it at all, so please excuse my pathetic stupid question if you find it to be, I'm using Phil Sturgeon's REST API server, Curl Library, and REST API client here's my code:

in my controller application/controllers/make_key

function index(){
      $this->load->library('rest');
      $this->load->library('curl');
      $this->rest->put('https://www.myapplication.com/apifolder/key/X-API-KEY/FOO');
    }

- no response at all

where apifolder/key is the location of my key.php (from Phil Sturgeon's default example):

and note that I've also tried this via address bar:

https://www.myapplication.com/apifolder/key/X-API-KEY/FOO - returns ({"status":false,"error":"Invalid API Key."})

https://www.myapplication.com/apifolder/key?X-API-KEY=FOO - returns ({"status":false,"error":"Unknown method."})

and tried quite a lot more queries but none seem to be working, my only question is...

How can make this key.php work? my apologies for such a simple minded question thank you in advance

解决方案

see my self-accepted answer on my own qeuestion... Phils documentation does not provide this information. I had to dig into the library myself.

i ended up finding out the 403 forbidden was because i was not providing an api key to generate keys..
Kind of abiguous as Phil's documentation doesn't state that an existing api key is required before you can generate keys.. I simply created a bogus key in the table in the db and referenced that when calling /key/index?X-API-KEY=boguskey

CodeIgniter REST API Library Ajax PUT throwing 403 Forbidden

这篇关于如何在Codeigniter中的我自己的控制器中生成API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆