[WordPress] 外掛分享: Datawiza Proxy Auth Plugin – SSO

首頁外掛目錄 › Datawiza Proxy Auth Plugin – SSO
全新外掛
安裝啟用
★★★★
4/5 分(1 則評價)
1605 天前
最後更新
問題解決
WordPress 3.0.1+ PHP 5.6+ v1.1.2 上架:2020-12-18

內容簡介

此外掛 Proxy Auth Plugin 可以幫助開發者、DevOps 和管理員透過使用反向代理所提供的 JSON Web Token (JWT) 簡單實作 WordPress 的驗證與授權功能。

這可用於透過識別感知代理 (Identity-Aware Proxy) (例如 Datawiza Access Broker 及 Google IAP) 實現 SSO (OAUTH/OIDC、SAML) 至雲端身份提供者 (例如 Azure Active Directory、Okta、Auth0)。

注意,此外掛需要反向代理位於 WordPress 網站前方。反向代理執行驗證,然後透過 HTTP 標頭傳遞使用者名稱和角色的 JWT 給此外掛,標頭名稱為 DW-TOKEN。

透過 Datawiza Access Broker,您可使用基於配置的無程式碼 (no-code) 解決方案,按照此處提供的詳細說明。

如果您決定使用自己的反向代理,請遵循以下說明。

使用方式:

1. 此外掛檢索 JWT 中的使用者 ID (電子郵件),然後檢查此類使用者是否存在。如果不存在,此外掛會使用此電子郵件創建新使用者並簽入。
2. 此外掛檢索 JWT 中的使用者角色,並將其設置為 WordPress 中的使用者角色。
3. 此外掛期望 JWT 包括使用者 ID 和角色作為 HTTP 標頭 DW-TOKEN。例如,JWT 的有效負載可能如下所示:

{
"role": "administrator",
"email": "[email protected]"
}

WordPress 中的外掛設定:

在「設定」-「Datawiza Proxy Auth」中,您需要輸入一個私密密鑰,用作加解密金鑰。該密鑰是插件與反向代理之間共享的。JWT 的簽署算法為 HS256。

注意事項:

1. 如果啟用的 Proxy Auth Plugin 無法檢索到 HTTP 標頭中預期的 JWT,則插件將無法運作,WordPress 將使用預設驗證,並在網頁頂部顯示錯誤橫幅。
2. 請確保客戶端無法繞過反向代理。這可防止人們直接向 WordPress 發送伪造的惡意請求,其中包含任意的 JWT。
3. 建議 WordPress 網站前方的反向代理擦除傳入 HTTP 請求的 DW-TOKEN 標頭。DW-TOKEN 標頭應僅由反向代理生成。
4. 如果管理員未向使用者分派角色,使用者的角色將默認為 WordPress 的訂閱者。
5. 如果 JWT 更新了使用者角色,此外掛將相應地更新 WordPress 中的角色。

生成此外掛所需的 JWT:

如果您使用 openresty/lua-nginx-module,下面是生成外掛所需的 JWT 的程式碼示例:

jwt = require("resty.jwt")
local jwt_token = jwt:sign(
"jwt_secret",
{
header={typ="JWT", alg="HS256"},
payload={email="[email protected]", role="administrator"}
}
)
ngx.req.set_header('DW-TOKEN', jwt_token)

上述 jwt_secret 應為「設定」-「Datawiza Proxy Auth」中輸入的相同私密密鑰。

外掛標籤

開發者團隊

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

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Datawiza Proxy Auth Plugin – SSO」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

The Proxy Auth Plugin helps developers/DevOps/admins easily implement authentication and authorization for WordPress by using a JWT (JSON Web Token) provided by a reverse proxy.
This could be employed to achieve SSO (OAUTH/OIDC and SAML) to a Cloud Identity Provider (e.g., Azure Active Directory, Okta, Auth0) by using an Identity-Aware Proxy, e.g., Datawiza Access Broker and Google IAP.
Note that the plugin requires a reverse proxy sitting in front of the WordPress site. The reverse proxy performs authentication, and passes the user name and role in a JWT to the plugin via a HTTP header called DW-TOKEN.
By using Datawiza Access Broker, you get a configuration-based no-code solution, following the detail instruction here.
If you decide to use your own reverse proxy, please follow the instructions below.
How it works

The plugin retrieves the user id (email) from the JWT and then checks if such a user exists. If not, the plugin creates a new user by using this email and signs him/her in.
The plugin retrieves the user role from the JWT and sets it as the user’s role in WordPress.

The plugin expects the JWT including user id and role as a HTTP header DW-TOKEN. For example, the payload of JWT may look like:
{
“role”: “administrator”,
“email”: “[email protected]
}

Plugin config in WordPress
In Setting -> Datawiza Proxy Auth, you need to input a private secret which is used as a Cryptography Key. Such secret is shared between the plugin and the reverse proxy which is responsible for passing the JWT to the plugin. The Signing Algorithm for the JWT is HS256.
!!! NOTES !!!

If the enabled Proxy Auth Plugin cannot retrieve the expected JWT in the HTTP header, the plugin will not work. The authentication will use the default authentication of wordpress and you will see an error banner on top of the wordpress pages.
MAKE SURE that clients cannot bypass the reverse proxy. This is to prevent people from sending forged malicious requests with arbitrary JWTs directly to WordPress.
It’s recommended that the reverse proxy in front of the WordPress site erases the incoming http request’s DW-TOKEN header. The DW-TOKEN header should be generated by the reverse proxy only.
If admin doesn’t assign role to the user, user’s role will be subscriber for WordPress by default.
If user’s role has been updated in JWT, the plugin will update the role in WordPress accordingly.

Generate the JWT required by the plugin
If you are using openresty/lua-nginx-module, here is the code sample to generate the JWT required by the plugin:
jwt = require("resty.jwt")
local jwt_token = jwt:sign(
"jwt_secret",
{
header={typ="JWT", alg="HS256"},
payload={email="[email protected]", role="administrator"}
})
ngx.req.set_header('DW-TOKEN', jwt_token)

The jwt_secret above should be the same private secret input in Setting -> Datawiza Proxy Auth. The role in payload is optional. If it’s not specified, the default role is subscriber. For more details about lua-resty-jwt, you can visit here.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon