【问题标题】:Impersonating another user in SoftLayer在 SoftLayer 中模拟另一个用户
【发布时间】:2017-03-10 21:27:57
【问题描述】:

我们在 SoftLayer 中有一个代理帐户,通过该帐户创建了多个客户帐户。我试图对客户帐户执行一些操作,但 API 不允许执行任何操作,因为我的 SoftLayer Python 客户端使用代理帐户的用户名/密码。

我浏览了很多帖子并冒充客户帐户的“SoftLayer_User_Customer”作为可能的解决方案,但没有太多关于如何使用它的细节。我能够使用getImpersanationToken 调用获得令牌,但我不确定如何使用它。

是否有任何示例说明如何从主品牌帐户以客户用户身份登录(使用模拟或其他方式)?

我正在使用 Softlayer Python API,但也尝试过使用 SOAP 调用。

【问题讨论】:

    标签: python ibm-cloud-infrastructure


    【解决方案1】:

    你需要的方法是这个:

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

    使用python客户端你会得到这样的:

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

    其中 userID 是您要获取令牌的用户的 ID,brandId 是您帐户的品牌 ID

    您需要使用这样的 SOAP 请求:

    <?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>
    

    上面的soap正在为你在上一个请求中获得令牌的用户调用http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer/addApiAuthenticationKey方法。

    不要忘记替换 SOAP 中的值 $USERID 和 $TOKEN

    问候

    【讨论】:

    • 非常感谢。工作得很好。使用 getApiAuthenticationKeys 也可以获得用户的 API 密钥,这样我们就可以继续使用 Python API。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 2021-01-09
    相关资源
    最近更新 更多