After a long time again I am here to resolve my problem. I am much new to Codeigniter framework. I just started learning RESTful api's in CodeIgiter. Then I got to Know about that we can use JWT instead of Sessions. I am able to use the JWT and generated the token successfully. Now the problem here is, I want to verify the generated token for every request from the client. for example, this is the basic url or api, http://localhost/codeigniter/api/
Now I want to verify something like this:
http://localhost/codeigniter/api?token="here the generated token will come"
How do I implement it, using Codeigniter 3.x
I am using codeigniter-rest server for API calls, and php-jwt to generate tokens.
first create a helper from code https://github.com/rmcdaniel/angular-codeigniter-seed/blob/master/api/application/helpers/jwt_helper.php
then load or auto load this helper.
This will give you the token
helper_name::encode(data, secure_key)
To verify you need to use
helper_name::decode(token,secure_key,true)
it will give you data which you have encoded or it will give you false if token is not valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With