简体   繁体   English

CodeIgniter REST服务器身份验证问题

[英]CodeIgniter REST Server authentication problems

I'm using this CodeIgniter REST Server project to implement a REST API. 我正在使用此CodeIgniter REST Server项目来实现REST API。

So far I have been able to do some basic tests calling a controller via GET, PUT, POST and DELETE with keys. 到目前为止,我已经能够进行一些基本测试,并通过GET,PUT,POST和DELETE键调用控制器。

Here's an example: 这是一个例子:

POST POST

curl -X POST -H "X-API-KEY: mAkS2FnJcXe8Whr8SbV0M6rJWMo3yNz6jgpV2ViL" http://jeanpaulruizvallejo.com/proyectos/pruebas/ci-rest-api/RestTestController/user/ --data "id=1"

Now, I need to be able to use username and passwords. 现在,我需要能够使用用户名和密码。 I have tried with several ways but have not been able to get it working. 我已经尝试了几种方法,但是无法使其正常工作。

I would like to get some help about how to implement a username and password authentication model working for this REST API. 我想获得有关如何实现适用于该REST API的用户名和密码身份验证模型的一些帮助。

Thanks in advance for the help. 先谢谢您的帮助。

My current config file for rest: 我当前休息的配置文件:

rest.php rest.php

if you want a user login api key gen or user sign up based system, you can set a override auth config variable in rest.php config file. 如果要使用用户登录api密钥生成或基于用户注册的系统,则可以在rest.php配置文件中设置替代auth配置变量。

Example : I want generate an api key when a user sign up with my controller "users" and my method "signup". 示例:当用户使用我的控制器“ users”和我的方法“ signup”进行注册时,我想生成一个api密钥。

I simply add : 我只需添加:

$config['auth_override_class_method']['users']['signup'] = 'none';

in

./application/config/rest.php (see L.144) ./application/config/rest.php(请参阅L.144)

That's all :) After this, you can generate a key in signup method and save the key in db before sending to client. 仅此而已:)之后,您可以在注册方法中生成密钥,并将密钥保存在db中,然后再发送给客户端。

Another method should be to set a api key as token into session userdata and configure rest.php with the name of this variable. 另一种方法应该是将api密钥作为令牌设置到会话userdata中,并使用此变量的名称配置rest.php。

I'm currently in the process of testing several of these methods and other implementations with codeigniter Rest. 我目前正在使用Codeigniter Rest测试其中的一些方法和其他实现。

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM