WSO2 Identity Server - How to assign an existing role to a WSO2 IS user?

前端 未结 2 1935
日久生厌
日久生厌 2021-01-15 17:50

I am using WSO2 Identity Server 4.1.0. My requirement is to assign an existing role to a user created in the WSO2 default identity store. I have tried the following:

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 18:32

    Use PATCH operation:

    Nodejs Sample code for SCIM2 (WSO2 Identity server 5.6):

    //roleId is GUID generated after creating group. 
    // token is the bearer token generated via client credential or password credential
    
    function assignRoleToUser(token, user, roleId) {
    var groupId = roleId;
    var rp = require('request-promise');
    var options = {
        uri:  + '/' + groupId,
        method: 'PATCH',
        json: true,
        headers: {
            'Content-Type': 'application/json',
            'Authorization': token
        },
        body:
        {
            schemas: ['urn:ietf:params:scim:api:messages:2.0:PatchOp'],
            Operations: [
                {
                    op: 'add',
                    value: {
                        members: [
                            {
                                display: user.userName,
                                value: user.id
                            }
                        ]
    
                    }
                }]
        }
    };
    return rp(options);
    

    }

    Only drawback of this API is that, it returns array containing all members of that group after success. Not optimized if group has thousands or millions of users.

提交回复
热议问题