Impersonating another user in SoftLayer

2020-05-08 08:08发布

We have an agent account in SoftLayer through which multiple Customer accounts have been created. Im trying to do some operations on the Customer account but the API isnt allowing any operations to be done since my SoftLayer Python Client uses the username/password of the agent account.

I browsed through a lot of posts and impersonating as the "SoftLayer_User_Customer" of the customer account was given as a possible solution but there isnt much detail as to how to use it. I was able to get a Token using the getImpersanationToken call, but Im unsure how to use this.

Are there any examples of how to login(Either using impersonation or another way) as a Customer User from a Master Brand Account?

Im using the Softlayer Python API but have tried this using the SOAP calls as well.

1条回答
老娘就宠你
2楼-- · 2020-05-08 08:52

the method that you need is this one:

http://sldn.softlayer.com/reference/services/SoftLayer_Brand/getToken

using the python client you will have something like this:

    token = client['SoftLayer_Brand'].getToken(userID, id=brandID)

where userID is the id of the user you want to get the token and the brandId is the brand id of your account

The you need to use a SOAP request like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.service.softlayer.com/soap/v3/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Header>
    <ns1:clientLegacySession>
      <userId>$USERID</userId>
      <authToken>$TOKEN</authToken>
    </ns1:clientLegacySession>
    <ns1:SoftLayer_User_CustomerInitParameters>
      <id>$USERID</id>
    </ns1:SoftLayer_User_CustomerInitParameters>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:addApiAuthenticationKey/>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The soap above is calling the method http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer/addApiAuthenticationKey for the user that you got the token in the previous request.

Not forget replace the values $USERID and $TOKEN in the SOAP

Regards

查看更多
登录 后发表回答