Mad*_*mar 2 php codeigniter restful-authentication jwt
经过很长一段时间,我来这里解决我的问题.我对Codeigniter框架很新.我刚开始在CodeIgiter中学习RESTful api.然后我知道我们可以使用JWT而不是Sessions.我能够使用JWT并成功生成令牌.现在问题是,我想为客户端的每个请求验证生成的令牌.例如,这是基本的url或api, http:// localhost/codeigniter/api /
现在我要验证这样的事情:
http://localhost/codeigniter/api?token="here the generated token will come"
Run Code Online (Sandbox Code Playgroud)
如何使用Codeigniter 3.x实现它
我使用codeigniter-rest服务器进行API调用,使用php-jwt生成令牌.
首先从代码https://github.com/rmcdaniel/angular-codeigniter-seed/blob/master/api/application/helpers/jwt_helper.php创建一个帮助器
然后加载或自动加载此帮助程序.
这将为您提供令牌
helper_name::encode(data, secure_key)
Run Code Online (Sandbox Code Playgroud)
验证您需要使用
helper_name::decode(token,secure_key,true)
Run Code Online (Sandbox Code Playgroud)
它会为您提供已编码的数据,如果令牌无效,它将为您提供错误.
| 归档时间: |
|
| 查看次数: |
13372 次 |
| 最近记录: |