問題描述
我正在嘗試按照以下指南使用來自 google 的新 firebase sdk 設置自定義身份驗證:https://firebase.google.com/docs/auth/server#use_a_jwt_library
在 samble 代碼中它說:
I'm trying to set up custom auth with the new firebase sdk from google following those guidelines : https://firebase.google.com/docs/auth/server#use_a_jwt_library
In the samble code it says :
從 JSON 密鑰文件中獲取您的服務帳號的電子郵件地址和私鑰
Get your service account's email address and private key from the JSON key file
不幸的是,我不知道從哪里獲得這個 json 文件.如果我去我的 firebase 控制臺 (https://console.firebase.google.com/) 我設法下載了一個 json文件,但它不包含任何電子郵件地址和私鑰.
Unfortunately I have not idea where to get this json file. If I go to my firebase console (https://console.firebase.google.com/) I manage to donwload a json file but it does not contain any email adress and private key.
我設法在我的 google 云平臺控制臺 (http://console.conf) 中找到了一個包含電子郵件地址和私鑰的 json 文件.cloud.google.com) 進入API Manager > Credentials"菜單.令人驚訝的是,我的 firebase 應用程序顯示在那里.我將電子郵件和密鑰復制并粘貼到示例代碼中,然后出現此錯誤:
I managed to find a json file that contains an email adress and a private key in my google cloud platform console (http://console.cloud.google.com) by goind into the "API Manager > Credentials" menu. Surprisingly my firebase app was showed there. I copy and pasted the email and key into the sample code, then I got this error :
警告:openssl_sign():無法將提供的密鑰參數強制轉換為第 183 行/volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php 中的私鑰致命錯誤:未捕獲的異常DomainException"' 在/volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php:185 中帶有消息 'OpenSSL 無法簽署數據' 堆棧跟蹤:#0/volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php(154): FirebaseJWTJWT::sign('eyJ0eXAiOiJKV1Q...', NULL, 'RS256') #1/volume1/web/yeti/jwt.php(21):FirebaseJWTJWT::encode(Array, NULL, 'RS256') #2/volume1/web/yeti/jwt.php(24): create_custom_token('1234', false) #3 {main} 被拋出到/volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php 第 185 行
Warning: openssl_sign(): supplied key param cannot be coerced into a private key in /volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php on line 183 Fatal error: Uncaught exception 'DomainException' with message 'OpenSSL unable to sign data' in /volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php:185 Stack trace: #0 /volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php(154): FirebaseJWTJWT::sign('eyJ0eXAiOiJKV1Q...', NULL, 'RS256') #1 /volume1/web/yeti/jwt.php(21): FirebaseJWTJWT::encode(Array, NULL, 'RS256') #2 /volume1/web/yeti/jwt.php(24): create_custom_token('1234', false) #3 {main} thrown in /volume1/web/yeti/vendor/firebase/php-jwt/src/JWT.php on line 185
有人知道我做錯了什么嗎?
Does someone has an idea of what I'm doing wrong ?
謝謝
推薦答案
您找到解決方案了嗎?仍然遇到同樣的問題!適用于 HS256,不適用于 RS256.這是谷歌云的限制嗎?
Did you find the solution ? Still experiencing the same issue ! Works with HS256 and doesn't with RS256. Is it google cloud kind of limitation ?
非常感謝!@dbburgess
Thank you so much ! @dbburgess
問題:使用了錯誤的密鑰和電子郵件.這些應在與 Firebase 項目對應的 GCP 憑據部分中生成.
Problem: Was using the wrong key and email. These should be generated in the Google Cloud credentials section that corresponds to the Firebase project.
解決方案:
- 轉到console.cloud.google.com".
- 選擇相關的 Firebase 項目.
- 然后是API 管理器"->憑據".
- 創建憑據"->服務帳戶密鑰"-> 選擇 JSON.
- 創建的文件將包含所需的private_key"&'client_email'.
填寫值:
$service_account_email = "autogeneratedemail@developer.gserviceaccount.com";$private_key = "-----開始私鑰----- SoneVeryVeryLongKey= -----結束私鑰----- ";$uid = 'UserToUseInFirebaseRules';$is_premium_account = $uid;
$service_account_email = "autogeneratedemail@developer.gserviceaccount.com"; $private_key = "-----BEGIN PRIVATE KEY----- SoneVeryVeryLongKey= -----END PRIVATE KEY----- "; $uid = 'UserToUseInFirebaseRules'; $is_premium_account = $uid;
您不需要更改create_custom_token"函數中的任何內容,也許可以根據您的需要更改到期日期/時間.
You shouldn't need to change anything in the "create_custom_token" function, maybe the expiration date/time according to your needs.
然后調用函數:
create_custom_token($uid, $is_premium_account);
這篇關于使用 php 設置 firebase v3 自定義身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!