php - Firebase 在 php 上创建自定义令牌始终在 php 上返回 null
问题描述
嗨,我正在使用 cakephp 作为后端,并希望为我的网站生成一个自定义令牌,该令牌将在我的客户端使用。下面是我生成自定义代码的代码
$activatedOfferwall = $session->read('ActiveOfferwall'); // 0209341c-da14-46b9-b3c9-8410472e13d2
$factory = (new Factory)->withServiceAccount(\App\Model\Constants\FirebaseConstants::JSON_FILE)->withDatabaseUri(\App\Model\Constants\FirebaseConstants::DEFAULT_URL);
$auth = $factory->createAuth();
$customToken = $auth->createCustomToken($activatedOfferwall['UserHash']);
Log::debug(json_encode($customToken));
火基地规则是
但这总是返回一个空的 json。我在这里想念什么?
解决方案
$generator = CustomTokenGenerator::withClientEmailAndPrivateKey(
$email,
$privateKey
);
$token = $generator->createCustomToken('anthony@gmail.com');
然后在客户端发送令牌
firebase.auth().signInWithCustomToken(usertoken)
.then((userCredential) => {
// Signed in
var user = userCredential.user;
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function(idToken) {
console.log(idToken)
}).catch(function(error) {
// Handle error
});
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
console.log(error);
// ...
});
推荐阅读
- php - 如何在 Laravel 中为(预定的)命令设置内存限制?
- oauth - 如何在 Cognito 中更改 SAML 身份验证的用户名
- flutter - Flutter 中手机和平板电脑上一致的相机预览旋转行为
- python-3.x - python中日期范围之间的月份开始日期和结束日期
- amazon-web-services - 从 Lambda 调用时,AWS API Gateway 403 被禁止
- javascript - 如何在 javascript 中使用 node-js 加密?
- python - Python Flask App 错误:'function' 对象没有使用 Flask-Dance 的属性'get'
- c# - DbContext.Database.Migrate() 方法在哪里?
- node.js - 使用 fetch 命令导致 self 中的“URLSearchParams”未定义
- ruby-on-rails - 包含模块如何在课堂内外工作