本文介紹OIDC標準協議的OIDC id_token擴充值填寫規範及配置樣本。
id_token擴充欄位填寫規則
id_token 擴充欄位的值分為變數、常量和運算式三種類型。填寫變數時直接輸入變數名,不加引號;填寫常量時必須使用英文雙引號("")包裹常量值。
類型 | 填寫值 | 說明 |
變數 直接填寫變數名,不加引號。 | user.username | 使用者名稱。 |
user.displayName | 顯示名稱。 | |
user.phone(已到期) | 手機號,不包含國際區號(已到期) | |
user.phoneNumber | 手機號,不包含國際區號。 | |
user.email | 郵箱。 | |
user.status | 使用者狀態,取值:
| |
user.primaryOrganizationalUnitId | 使用者所屬主組織ID。 | |
user.organizationalUnits | 使用者所屬組織所有資訊。 | |
ArrayMap(user.organizationalUnits, __item.organizationalUnitId) | 使用者所屬所有組織ID。 格式:JSON數組。 | |
user.groups | 賬戶所屬組,組的所有資訊。 格式:JSON數組 | |
ArrayMap(user.groups, __item.groupId) | 賬戶所屬組ID列表 格式:JSON數組 | |
ArrayMap(user.groups, __item.groupExternalId) | 賬戶所屬組外部ID列表 格式:JSON數組 | |
user.customFields | 所有擴充欄位資訊 格式:JSON數組 | |
user.customFieldMap.$fieldname$.fieldValue | 某個擴充欄位的值 | |
常量 | 使用英文雙引號("")包裹常量值。例如填寫 "example_value"。 | |
運算式 | 進階功能,可以靈活地將值進行拼接、變化。 具體功能請參考進階賬戶欄位運算式。 | |
輸入樣本:(user對象)
{
...
"customFieldMap": {
"place": {
"fieldName": "place",
"fieldValue": "beijing"
},
"age": {
"fieldName": "age",
"fieldValue": "18"
}
},
"identityProviderUserMap": {
"idp_m2gngriuenktdkxxxxxx": {
"identityProviderId": "idp_m2gngriuenktdkxxxxxx",
"identityProviderType": "ding_talk",
"identityProviderExternalId": "corp_1234xxxxxxx",
"identityProviderUserId": "b2ed5fc0xxxxx"
}
},
"organizationalUnits": [
{
"organizationalUnitId": "ou_sdfadtaaxxxxxx",
"organizationalUnitName": "AD",
"primary": false
},
{
"organizationalUnitId": "ou_werttxxxxxx",
"organizationalUnitName": "name_002",
"primary": true
}
],
"primaryOrganizationalUnitId": "ou_werttxxxxxx",
"customFields": [
{
"fieldName": "place",
"fieldValue": "beijing"
},
{
"fieldName": "age",
"fieldValue": "18"
}
],
"groups": [
{
"groupId": "group_jp6al4sn4n4wjgjxxxxxx",
"groupName": "group1",
"groupExternalId": "group_jp6al4sn4n4wjgjxxxxxx"
},
{
"groupId": "group_vavikcxewkf5h3oxxxxxx",
"groupName": "group2",
"groupExternalId": "group_vavikcxewkf5h3oxxxxxx"
}
],
...
}OIDC運算式相關樣本
在 IDaaS 的應用頁面,單擊隱藏進階配置展開進階配置地區,在擴充 id_token地區通過雙列映射表添加擴充欄位名與對應運算式。
通過運算式user.organizationalUnits進行id_token解析後:
[ { "organizationalUnitId": "ou_sdfadtaaxxxxxx", "organizationalUnitName": "AD", "primary": false }, { "organizationalUnitId": "ou_werttxxxxxx", "organizationalUnitName": "name_002", "primary": true } ]通過運算式ArrayMap(user.organizationalUnits, __item.organizationalUnitId)進行id_token解析後:
[ "ou_sdfadtaaxxxxxx", "ou_werttxxxxxx" ]通過運算式user.groups進行id_token解析後:
[ { "groupId": "group_jp6al4sn4n4wjgjxxxxxx", "groupName": "group1", "groupExternalId": "group_jp6al4sn4n4wjgjxxxxxx" }, { "groupId": "group_vavikcxewkf5h3oxxxxxx", "groupName": "group2", "groupExternalId": "group_vavikcxewkf5h3oxxxxxx" } ]通過運算式ArrayMap(user.groups, __item.groupId)進行id_token解析後:
[ "group_jp6al4sn4n4wjgjxxxxxx", "group_vavikcxewkf5h3oxxxxxx" ]通過運算式ArrayMap(user.groups, __item.groupExternalId)進行id_token解析後:
[ "group_jp6al4sn4n4wjgjxxxxxx", "group_vavikcxewkf5h3oxxxxxx" ]通過運算式user.customFields進行id_token解析後:
[ { "fieldName": "place", "fieldValue": "beijing" }, { "fieldName": "age", "fieldValue": "18" } ]通過運算式user.customFieldMap.age.fieldValue進行id_token解析後:
18
id_token擴充欄位重寫規則
預設欄位規則
系統預設欄位不支援重寫:
exp,nbf,iat,iss,jti,at_hash,c_hash,nonce,sid。支援重寫欄位:
sub。
使用者資訊欄位規則
使用者 id_token 中的以下欄位根據 scope 判斷是否可重寫:
欄位名稱 | 關聯scope | 不可重寫條件 |
email, email_verified | 當scope包含email且使用者email不為空白時 | |
phone_number, phone_number_verified | phone | 當scope包含phone且使用者phoneNumber不為空白時 |
name, preferred_username, updated_at, locale | profile | 當scope包含profile時 |
instance_id, application_id | instance | 當scope包含instance時 |
配置建議
在使用者資訊範圍配置中謹慎選擇scope,因為這將影響哪些使用者欄位可以被重寫。
如果需要重寫特定欄位,請確保:未包含對應的scope或對應的使用者欄位為空白值。