簡體   English   中英

使用“Pre Token Generation Lambda Trigger Function”時,如何設置“claimsToAddOrOverride”以返回數組而不是字符串

[英]When using the "Pre Token Generation Lambda Trigger Function", how do I set the "claimsToAddOrOverride" to return an array instead of a string

我編寫了預令牌生成 Lambda 觸發器 function 以將自定義字符串屬性拆分為數組並分配給新屬性,字符串屬性的格式為“FDVC443FD|HFVSD4434”。 然后 lambda function 應該創建數組 ["FDVC443FD", "HFVSD4434"] 並將其分配給新屬性。

預期結果 輸入 -> "custom:eaid": "FDVC443FD|HFVSD4434" Output -> "eaid": ["FDVC443FD", "HFVSD4434"]

預令牌生成 Lambda 觸發器 Function(Python)

def lambda_handler(event, context):
#This function handles adding a custom claim to the cognito ID token.# grab requestor's custom external id (eaid)
custom_eaid = event['request']['userAttributes']['custom:eaid']

# Split the custom attribute string into an array by the "|" seperator
custom_eaid = custom_eaid.split('|')

# placeholder variable
eaid = ''

# this allows us to override claims in the id token
# "claimsToAddOrOverride" is the important part 
event["response"]["claimsOverrideDetails"] = { 
    "claimsToAddOrOverride": { 
        "eaid": custom_eaid
    },
    "claimsToSuppress": ["custom:eaid"]
} 
     
# return modified ID token to Amazon Cognito 
return event

Lambda function 返回以下錯誤:-

在“https://cognito-idp.eu-west-1.amazonaws.com\”上執行“InitiateAuth”時出錯; AWS HTTP 錯誤:客戶端錯誤:POST https://cognito-idp.eu-west-1.amazonaws.com導致 400 錯誤請求響應:\n{"__type":"InvalidLambdaResponseException","message":"Unrecognizable lambda 輸出”}\n InvalidLambdaResponseException(客戶端):無法識別 lambda output - {“__type”:“InvalidLambdaResponseException”,“消息”:“無法識別 lambda 輸出”}

根據文檔claimsToAddOrOverride需要一組string鍵/值對。

所以到目前為止,我們不能將列表作為值傳遞。

也許您可以嘗試使用逗號分隔的字符串或按原樣設置custom:eaid 然后,每當您需要將其作為列表時,從聲明中提取它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM