tem*_*mp_ 6 php firebase server firebase-authentication
在我的服务器上,我运行了几个读取我的Firebase实时数据库的PHP文件.根据Firebase的文档,我需要设置自定义令牌以使我的Firebase PHP客户端运行.Firebase文档说我需要退货;
return JWT::encode($payload, $private_key, "RS256");
Run Code Online (Sandbox Code Playgroud)
我究竟如何参考JWT课程?我下载了一个JWT库,但我不知道如何在我的项目中实现它.任何帮助都会很棒,我主要是一名移动开发人员,对PHP几乎没有经验.
son*_*nam 19
firebase/php-jwt库使用composer.如果你来自android开发背景,Composer是PHP的依赖管理器,类似于Java中的Maven.您需要知道如何使用php的require/include函数在php中导入类.你需要一些使用php的经验来使用composer.
为了使用没有composer的firebase/php-jwt库你可以使用下面的示例代码:(我在'jwt'文件夹下载了库)
<?php
require_once 'jwt/src/BeforeValidException.php';
require_once 'jwt/src/ExpiredException.php';
require_once 'jwt/src/SignatureInvalidException.php';
require_once 'jwt/src/JWT.php';
use \Firebase\JWT\JWT;
$key = "example_key";
$token = array(
"iss" => "http://example.org",
"aud" => "http://example.com",
"iat" => 1356999524,
"nbf" => 1357000000
);
/**
* 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($token, $key);
$decoded = JWT::decode($jwt, $key, array('HS256'));
print_r($decoded);
/*
NOTE: This will now be an object instead of an associative array. To get
an associative array, you will need to cast it as such:
*/
$decoded_array = (array) $decoded;
/**
* You can add a leeway to account for when there is a clock skew times between
* the signing and verifying servers. It is recommended that this leeway should
* not be bigger than a few minutes.
*
* Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
*/
JWT::$leeway = 60; // $leeway in seconds
$decoded = JWT::decode($jwt, $key, array('HS256'));
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7690 次 |
最近记录: |