/** * Test the encryption and decryption of the token data */ public function testEncryptDecryptToken() { $encryptKey = 'test1234'; $header = new Header('test'); $jwt = new Jwt($header); $jwt->issuer('http://example.org')->audience('http://example.com')->issuedAt(1356999524)->notBefore(1357000000)->expireTime(time() + 3600)->jwtId('id123456')->type('https://example.com/register')->custom('test', 'claim1'); $result = $jwt->encrypt('AES-256-CBC', '1234567812345678', $encryptKey); $result = $jwt->decrypt($result, 'AES-256-CBC', '1234567812345678', $encryptKey); $this->assertEquals($result->aud, 'http://example.com'); }
/** * Constructor. * @param array $header * @param array $payload */ public function __construct(array $header, array $payload) { $this->header = JoseHeader::parseFromArray($header); $this->payload = Jwt::parseFromArray($payload); }
/** * 产生28位 openid * @param $clientID * @param $user_id 用户在服务端登录id * @return string */ protected function generateOpenID($clientID, $user_id) { $str = substr($clientID, 0, 6); $str .= substr(md5($user_id, false), 0, 15); $encryptionUtil = new Jwt(); $str = $encryptionUtil->urlSafeB64Encode($str); return $str; }
/** * Refresh the user JWT token, default user data is the current user session * @param bool $user_data * @return bool */ public function refreshJWTtoken($user_data = false) { if ($user_data === false) { if (Core::$loggedIn === false) { return false; } $user_data = $_SESSION['currentuser']; } if (Core::$loggedIn !== false) { // Set a JWT Token $Jwt = new Jwt(ADVANCEDLOGINSCRIPT_SECRET_KEY); $JwtToken = $Jwt->createToken($user_data); if ($JwtToken !== false) { $_SESSION['currentuser']['jwt_token'] = $JwtToken; $this->setCookie(ADVANCEDLOGINSCRIPT_REMEMBER_ME_COOKIE . '_JWT_COOKIE', $JwtToken); } } }