[WordPress] 外掛分享: Verify ID Tokens | Firebase

首頁外掛目錄 › Verify ID Tokens | Firebase
全新外掛
安裝啟用
尚無評分
2552 天前
最後更新
問題解決
WordPress 4.7.0+ v1.0.0 上架:2019-03-24

內容簡介

如果您的 Firebase 客戶端應用程式與自訂的後端伺服器通訊,您可能需要在該伺服器上識別目前已登入的使用者。

這個外掛使用 Google Firebase 權杖。您可以使用它來驗證 ID 權杖。

命名空間與端點

當啟用外掛時,會添加一個新的命名空間

/verify-id-tokens/v1/

同時,此命名空間還會新增一個端點

/verify-id-tokens/v1/token/validate | POST

啟用 PHP HTTP 授權標頭

大多數共享主機預設已停用 HTTP 授權標頭。

若要啟用此選項,您需要編輯您的 .htaccess 檔案,並加入以下內容:

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

WPENGINE

若要啟用此選項,您需要編輯您的 .htaccess 檔案,並加入以下內容:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

設定 Firebase 專案 ID

若要新增專案 ID,請編輯您的 wp-config.php 檔案,並新增一個名為 BENGAL_STUDIO_VERIFY_ID_TOKENS_FIREBASE_PROJECT_ID 的常數。

define('BENGAL_STUDIO_VERIFY_ID_TOKENS_FIREBASE_PROJECT_ID', 'projectId');

設定跨來源資源共用(CORs)

Verify ID Tokens | Firebase 外掛提供啟用跨來源資源共用 (CORs)回應標頭的選項。

若要啟用 CORs,請編輯您的 wp-config.php 檔案,並新增一個名為 BENGAL_STUDIO_VERIFY_ID_TOKENS_ENABLE_CORS 的常數。

define('BENGAL_STUDIO_VERIFY_ID_TOKENS_ENABLE_CORS', true);

從客戶端擷取 ID 權杖

若要從客戶端擷取 ID 權杖,請確保使用者已登入,然後從已登入的使用者取得 ID 權杖:

firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
// 透過 HTTPS 將權杖傳送到您的後端伺服器
// ...
}).catch(function(error) {
// 處理錯誤
});

驗證 ID 權杖
verify-id-tokens/v1/token/validate

這是一個簡單的輔助端點,可用於驗證權杖;您只需要發送帶有授權標頭的 POST 請求即可。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Verify ID Tokens | Firebase」→ 直接安裝(推薦)

原文外掛簡介

If your Firebase client app communicates with a custom backend server, you might need to identify the currently signed-in user on that server.
This plugin work with Google Firebase tokens. You can use it to verify ID Tokens.
Namespace and Endpoints
When the plugin is activated, a new namespace is added
/verify-id-tokens/v1/

Also, a new endpoint is added to this namespace
/verify-id-tokens/v1/token/validate | POST
PHP HTTP Authorization Header enable
Most of the shared hosting has disabled the HTTP Authorization Header by default.
To enable this option you’ll need to edit your .htaccess file adding the follow
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

WPENGINE
To enable this option you’ll need to edit your .htaccess file adding the follow
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Configurate the Firebase projectId
To add the projectId edit your wp-config.php file and add a new constant called BENGAL_STUDIO_VERIFY_ID_TOKENS_FIREBASE_PROJECT_ID
define('BENGAL_STUDIO_VERIFY_ID_TOKENS_FIREBASE_PROJECT_ID', 'projectId');

Configurate CORs
The Verify ID Tokens | Firebase plugin has the option to activate CORs response headers.
To enable the CORs edit your wp-config.php file and add a new constant called BENGAL_STUDIO_VERIFY_ID_TOKENS_ENABLE_CORS
define('BENGAL_STUDIO_VERIFY_ID_TOKENS_ENABLE_CORS', true);

Retrieve ID tokens on clients
To retrieve the ID token from the client, make sure the user is signed in and then get the ID token from the signed-in user:
firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
// Send token to your backend via HTTPS
// ...
}).catch(function(error) {
// Handle error
});

Verify ID Tokens
verify-id-tokens/v1/token/validate
This is a simple helper endpoint to validate a token; you only will need to make a POST request sending the Authorization header.

延伸相關外掛

文章
Filter
Mastodon