適用於:
Databricks SQL
執行時間 19 及以上
回傳驗證當前會話的 OAuth 憑證中的自訂身份聲明。 應用程式在請求服務主體的 OAuth 令牌時,會加入該聲明。 在動態檢視或列篩選函式中使用此函式,為應用程式的每個終端使用者過濾資料。 請參閱 「依終端使用者篩選資料與 OAuth 自訂身份聲明」。
Syntax
current_oauth_custom_identity_claim()
Arguments
這個函數沒有引數。
Returns
A STRING。
如果該會話未使用帶有自訂身份聲明的 OAuth 憑證認證,函式會回傳 NULL。
註釋
- 將所有使用此函式的過濾器寫入,讓某個
NULL主張不符合任何列。 使用純等式,例如customer_name = current_oauth_custom_identity_claim()。 不要在申請時使用IS NULL檢查coalesce,或是空安全等號運算子<=>。 請參閱當 主張為 NULL 時,寫入任何列不匹配的篩選器。 - 請僅將理賠當作比較價值。 不要把它當作
RLIKE在 中作為物件名稱IDENTIFIER的模式,或是執行的 SQL 文字EXECUTE IMMEDIATE的一部分。 - Azure Databricks 不會加密或解讀該聲明。 持有令牌的人都能閱讀。
Examples
-- A token created with custom_claim=acme
> SELECT current_oauth_custom_identity_claim();
acme
-- A token without a custom claim
> SELECT current_oauth_custom_identity_claim();
NULL
-- A dynamic view that returns only the caller's rows
> CREATE VIEW main.sales.customer_orders AS
SELECT order_id, customer_name, product, order_date
FROM main.sales.orders
WHERE customer_name = current_oauth_custom_identity_claim();