current_oauth_custom_identity_claim function

适用于:检查标记为“是”的 Databricks SQL 检查标记为“是”是 Databricks Runtime 19 及更高版本

返回认证当前会话的OAuth令牌中的自定义身份声明。 应用程序在请求服务主体的OAuth令牌时添加该声明。 在动态视图或行过滤函数中使用此函数,为应用的每个终端用户过滤数据。

Syntax

current_oauth_custom_identity_claim()

Arguments

此函数没有参数。

Returns

STRING。

如果会话未使用带有自定义身份声明的OAuth令牌进行认证,函数 NULL返回 。

Notes

  • 写入所有使用该函数的过滤器,使得理 NULL 语句不匹配任何行。 使用纯等式,如 customer_name = current_oauth_custom_identity_claim()。 不要在理赔时使用 IS NULL 检查 coalesce,或者用空安全等价算子 <=> 。

  • 只用理赔作为比较价值。 不要将它用作 RLIKE 中的模式、IDENTIFIER 中的对象名称,或作为 EXECUTE IMMEDIATE 运行的 SQL 文本的一部分。

  • 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();