Beispiel #1
0
 /**
  * Enqueue script for settings page
  *
  * @return void
  */
 public function enqueue()
 {
     wp_enqueue_style('firechat', 'https://cdn.firebase.com/libs/firechat/2.0.1/firechat.min.css', '', '2.0.1');
     wp_enqueue_style('chat', FIRECHAT_URL . 'css/admin/chat.css', '', '1.0.0');
     wp_register_script('firebase', 'https://cdn.firebase.com/js/client/2.0.2/firebase.js', array('jquery'), '2.0.2', true);
     wp_register_script('firechat', 'https://cdn.firebase.com/libs/firechat/2.0.1/firechat.min.js', array('firebase'), '2.0.1', true);
     wp_enqueue_script('chat', FIRECHAT_URL . 'js/admin/chat.js', array('firechat'), '1.0.0', true);
     $user = wp_get_current_user();
     $option = get_option('firechat', array('url' => '', 'secret' => ''));
     // Add Firechat library
     if (!class_exists('JWT')) {
         require_once FIRECHAT_DIR . 'lib/JWT.php';
     }
     if (!class_exists('Services_FirebaseTokenGenerator')) {
         require_once FIRECHAT_DIR . 'lib/FirebaseToken.php';
     }
     $tokenGen = new Services_FirebaseTokenGenerator($option['secret']);
     $token = $tokenGen->createToken(array('uid' => 'user-' . $user->ID), array('admin' => current_user_can('manage_options')));
     wp_localize_script('chat', 'Chat', array('uid' => $user->ID, 'token' => $token, 'authError' => __('Error authentication', 'firechat'), 'name' => $user->user_login, 'firebaseUrl' => $option['url']));
 }
Beispiel #2
0
<?php

FileApi::extend('firepad_init', function ($self) {
    $cls = get_class($self);
    $secret = $cls::$firebase_secret;
    $url = $cls::$firebase_url;
    if (!$secret || !$url) {
        $ret = array('error' => 'Please define $firebase_secret and $firebase_url in your API class');
    } else {
        require_once __DIR__ . "/lib/JWT.php";
        require_once __DIR__ . "/lib/FirebaseToken.php";
        $tokenGen = new Services_FirebaseTokenGenerator($secret);
        $token = $tokenGen->createToken(array("uid" => "1"));
        $ret = array('token' => $token, 'url' => $url);
    }
    echo json_encode($ret);
});
 public function testObjectIsTreatedAsArray()
 {
     $token = $this->generator->createToken((object) ['uid' => 'uid']);
     $data = $this->decodeToken($token);
     $this->assertEquals('uid', $data->d->uid);
 }
<?php

header('Access-Control-Allow-Origin: *');
include_once "FirebaseToken.php";
$uid = "custom:" . $_POST['uid'];
$level = $_POST['level'];
$tokenGen = new Services_FirebaseTokenGenerator("<enter your firebase secretkey here>");
$token = $tokenGen->createToken(array("uid" => $uid, "level" => $level), array("admin" => False));
echo $token;
 /**
  * User Authentication
  *
  * @since   1.0.0
  * @return  string
  * @author  Alberto Ruggiero
  */
 public function user_auth()
 {
     if (empty($this->options['firebase-appsecret'])) {
         return;
     }
     $token_gen = new Services_FirebaseTokenGenerator(esc_html($this->options['firebase-appsecret']));
     $prefix = is_user_logged_in() && !defined('YLC_OPERATOR') ? 'usr-' : '';
     $data = array('uid' => $prefix . $this->user->ID, 'is_operator' => defined('YLC_OPERATOR') ? true : false);
     $opts = array('admin' => current_user_can('manage_options') ? true : false, 'debug' => true);
     return $token_gen->createToken($data, $opts);
 }
 /**
  * Authentication user
  *
  * @access public
  * @return string Auth token
  */
 public function auth()
 {
     global $wpdb;
     if (empty($this->opts['app_token'])) {
         return;
     }
     // FireBase authentication
     $token_gen = new Services_FirebaseTokenGenerator($this->opts['app_token']);
     // Administrator user?
     $is_admin = current_user_can('manage_options') ? true : false;
     // Is Operator?
     $is_op = defined('CX_OP') ? true : false;
     $prefix = is_user_logged_in() && !defined('CX_OP') ? 'usr-' : '';
     // An object or array of data you wish
     // to associate with the token. It will
     // be available as the variable "auth" in
     // the Firebase rules engine.
     $data = array('user_id' => $prefix . $this->user->ID, 'is_operator' => $is_op);
     $debug = !empty($this->opts['debug']) ? true : false;
     // Options
     $opts = array('admin' => $is_admin, 'debug' => $debug);
     // Create secure auth token
     return $token_gen->createToken($data, $opts);
 }
Beispiel #7
0
$loggedIn = false;
if (isloggedin()) {
    $loggedIn = true;
    if (strlen($secret) > 5 && strlen($appid) > 5) {
        $expire = 0;
        if (isset($_SESSION[$USER->sesskey . "rtmtoken" . $crowdmod->get_parent_id()])) {
            if (isset($_SESSION[$USER->sesskey . "rtmexpire" . $crowdmod->get_parent_id()])) {
                $expire = $_SESSION[$USER->sesskey . "rtmexpire" . $crowdmod->get_parent_id()];
            }
            if ($expire > time() + 1 * 3600) {
                //If we have 1 hours left or more
                $rtmtoken = $_SESSION[$USER->sesskey . "rtmtoken" . $crowdmod->get_parent_id()];
            }
        }
        if (!$rtmtoken) {
            $tokenGen = new Services_FirebaseTokenGenerator($secret);
            $rtmtoken = $tokenGen->createToken(array("app_id" => $appid, "user_id" => $USER->id, "processid" => $crowdmod->get_parent_id(), "user_name" => $USER->firstname . " " . $USER->lastname));
            $expire = time() + 24 * 3600;
            $_SESSION[$USER->sesskey . "rtmtoken" . $crowdmod->get_parent_id()] = $rtmtoken;
            $_SESSION[$USER->sesskey . "rtmexpire" . $crowdmod->get_parent_id()] = $expire;
        }
    }
} else {
    echo '<html><body><div>Por favor <a href="' . $CFG->wwwroot . '/login/index.php">Ingresar</a> antes de usar esta aplicación</div></body></html>';
    die;
}
//.. if not we create our front end.
?>
<!DOCTYPE html>
<html ng-app="delphiApp" ng-init="initConfig(<?php 
echo $cmid;