This topic provides the download URLs of the PHP SDK packages that are required for you to use STS. This topic also describes how to use the STS SDK for PHP.

Download URLs

Use the STS SDK for PHP

<?php
namespace AlibabaCloud\Tests\Feature;
use AlibabaCloud\Sts\Sts;
use PHPUnit\Framework\TestCase;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Sts\V20150401\AssumeRole;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Client\Exception\ClientException;
/**
 * Class StsTest
 *
 * @package   AlibabaCloud\Tests\Feature
 */
class StsTest extends TestCase
{    
    /**
     * @expectedException \AlibabaCloud\Client\Exception\ServerException
     * @expectedExceptionMessageRegExp /EntityNotExist.Role: The specified Role not exists/
     * @throws ClientException
     * @throws ServerException
     */
    // Construct an AssumeRole request.
    public function testSts()
    {
        // When you construct the client, set the AccessKey ID and AccessKey secret.      
        AlibabaCloud::accessKeyClient('LTAI4Ftm6BWGjEuusQzg****', 'W4ePhh5ArgySotqktAwXsSayQX****');
        Sts::v20150401()
           ->assumeRole()
           // Specify the Alibaba Cloud Resource Name (ARN) of the RAM role.
           ->withRoleArn('acs:ram::151266687691****:role/cloud')
           // Specify a role session name, which is used to identify the RAM user who assumes the RAM role.
           ->withRoleSessionName('client_name')
           // Specify a policy to grant the returned STS token fewer permissions than those granted to the RAM role.
           // The policy that is used in this example allows read-only access to all Object Storage Service (OSS) resources.
           ->withPolicy('{
             "Statement":[
                {
                     "Action":
                 [
                     "oss:Get*",
                     "oss:List*"
                     ],
                      "Effect": "Allow",
                      "Resource": "*"
                }
                   ],
          "Version": "1"
        }')
           ->connectTimeout(60)
           ->timeout(65)
           ->request();
    }
}
Note
  • For the list of STS endpoints in different regions, see Endpoints.
  • For more information about the AssumeRole API operation, see AssumeRole.