AWS Cognito - create groups from ADFS as Cognito Groups

前端 未结 2 1566
梦如初夏
梦如初夏 2021-01-06 04:36

An app is communicating via the Open ID Connect protocol with AWS Cognito, which is connected to ADFS, communicating via SAML. Cognito is e

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 04:58

    I had the same issue, and I have not found a static mapping option in Cognito either.

    The only way I see is to map the AD groups to custom:adgroups attribute in Cognito, and set up a Cognito "Pre Token Generation" lambda trigger. The lambda reads the value of the custom:adgroups and manually overrides the user's Cognito groups.

    NB - this does not change the cognito user's group permanently, only for the current session, but from the application perspective that's exactly what I needed.

    Please see a dummy static (non conditional) ADMIN group assignment example here:

    def lambda_handler(event, context):
    print(f'incoming event: {json.dumps(event)}')
    
    # manual cognito group override
    if event['triggerSource'] == "TokenGeneration_HostedAuth":
        event['response'] = {
                "claimsOverrideDetails": {
                    "groupOverrideDetails": {
                        "groupsToOverride": [
                            "ADMIN"
                        ]
                    }
                }
            }
    
    return event
    

    More detailed documentation here: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-token-generation.html

提交回复
热议问题