JWT(JSON Web Token) Creation (Without CURL) in CodeIgniter 3

 <?php

defined("BASEPATH") or exit("No direct script access allowed");

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

//Below is JWT Token Creation without CURL

class Token extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $key = 'example_key';
        $payload = [
            'iss' => 'http://heer.org',
            'aud' => 'http://heer.com',
            "email" => "Mahesh@gmail.com",
            'iat' => time()
        ];

        /**
         * IMPORTANT:
         * You must specify supported algorithms for your application. See
         * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
         * for a list of spec-compliant algorithms.
         */
        $jwt = JWT::encode($payload, $key, 'HS256');
        print_r($jwt);

        $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
        echo "<pre>";
        print_r($decoded);
    }
}



Comments