Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify JWT Token in CodeIgniter 3.x for every request from Client

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.

like image 410
Madhu Kumar Avatar asked Dec 18 '22 11:12

Madhu Kumar


1 Answers

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.

like image 76
ROHIT SAHA Avatar answered Jan 05 '23 06:01

ROHIT SAHA