/** * @param $secret * @param $uid * @param bool $admin * @throws TokenException */ public function generateToken($secret, $uid, $admin = false) { $tokenGenerator = new TokenGenerator($secret); $tokenGenerator->setData(['uid' => $uid]); if ($admin) { $tokenGenerator->setOption('admin', true); } $this->token = $tokenGenerator->create(); }
/** * @expectedException \Firebase\Token\TokenException */ public function testTriggerExceptionOnJwtException() { $this->generator->setData(['uid' => "±1"])->create(); }
<?php require 'vendor/autoload.php'; use Firebase\Token\TokenException; use Firebase\Token\TokenGenerator; try { $generator = new TokenGenerator('3u8lBgQGl8xGVldaXx4iI7hE3p5pbn7N22ifdKMH'); $token = $generator->setData(array('uid' => '32215'))->create(); } catch (TokenException $e) { echo "Error: " . $e->getMessage(); } echo $token;
<?php include_once "vendor/autoload.php"; use Firebase\Token\TokenException; use Firebase\Token\TokenGenerator; $usern = isset($_GET["user"]) ? $_GET["user"] : "******"; try { $generator = new TokenGenerator('YeKaaJU14OtA9Q8BK5v1NzTHC1pTTmwpnbA3O1lv'); $token = $generator->setData(array('uid' => $usern, 'displayName' => $usern))->create(); } catch (TokenException $e) { echo "Error: " . $e->getMessage(); } //echo $token; ?> <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <!-- jQuery --> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script> <!-- Firebase --> <script src='bower_components/firebase/firebase.js'></script> <!-- Firechat --> <link rel='stylesheet' href='bower_components/firechat/dist/firechat.min.css'/> <script src='bower_components/firechat/dist/firechat.min.js'></script> </head> <body>
require 'vendor/autoload.php'; use Firebase\Token\TokenException; use Firebase\Token\TokenGenerator; if ($_GET['trip']) { // Enable anonymous authentication and put in your firebase secret $secret = 'your_firebase_secret'; $sequence = $_GET['trip']; try { $generator = new TokenGenerator($secret); $token = $generator->setOption("admin", true)->create(); $sequence_share_check_url = 'https://motorbike-tracker.firebaseio.com/sequences/' . $sequence . '/share.json?auth=' . $token; $ch = curl_init($sequence_share_check_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); if (strpos($result, "true") >= 0) { $generator = new TokenGenerator($secret); $expires = time() + 3600; $token = $generator->setData(['uid' => 'uid', 'provider' => 'anonymous'], ['expires' => $expires])->create(); echo "var token = '" . $token . "'; var shared_trip='" . $sequence . "';"; } } catch (TokenException $e) { } } else { } ?> $(document).ready(function() { logout(); $('.selectpicker').selectpicker(); $(function () { $('[data-toggle="tooltip"]').tooltip();
public function add_firebase_token() { if (session_status() == PHP_SESSION_NONE) { session_start(); } // If exists and session is not active. if (isset($_SESSION['firebase_token'])) { $token_obj = unserialize($_SESSION['firebase_token']); $ttl = $token_obj['ttl']; if (time() < $ttl) { // echo "<script> var firebase_JWT = '{$token_obj['token']}'; </script>"; $this->renderFirebaseToken($token_obj['token']); return; } } if (get_post_type() !== 'poll') { return; } $secret = get_field('agreable_poll_plugin_settings_firebase_secret', 'options'); $user = get_field('agreable_poll_plugin_settings_senti_user_id', 'options'); if (empty($secret) || empty($user)) { $missing = empty($secret) ? "'Firebase secret'" : ''; $missing .= empty($secret) === true && empty($user) === true ? ' and ' : ''; $missing .= empty($user) ? "'Senti User ID'" : ''; Notifier::warning("Your are missing settings, which will cause Polls to not function correctly ({$missing}). Please contact the development/digital team."); return; } // include_once "FirebaseToken.php"; $token_generator = new TokenGenerator($secret); $token = $token_generator->setData(array("uid" => $user))->create(); $_SESSION['firebase_token'] = serialize(array('ttl' => time() + 60 * 60 * 24, 'token' => $token)); $this->renderFirebaseToken($token); }