1. Go to this page and download the library: Download alibabacloud/credentials library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alibabacloud / credentials example snippets
use AlibabaCloud\Credentials\Credential;
// Chain Provider if no Parameter
// Do not specify a method to initialize a Credentials client.
$client = new Credential();
$credential = $client->getCredential();
$credential->getAccessKeyId();
$credential->getAccessKeySecret();
$credential->getSecurityToken();
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Credentials\Credential\Config;
// Access Key
$config = new Config([
'type' => 'access_key',
'accessKeyId' => '<access_key_id>',
'accessKeySecret' => '<access_key_secret>',
]);
$client = new Credential($config);
$credential = $client->getCredential();
$credential->getAccessKeyId();
$credential->getAccessKeySecret();
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Credentials\Credential\Config;
$config = new Config([
'type' => 'sts',
'accessKeyId' => '<access_key_id>',
'accessKeySecret' => '<access_key_secret>',
'securityToken' => '<security_token>',
]);
$client = new Credential($config);
$credential = $client->getCredential();
$credential->getAccessKeyId();
$credential->getAccessKeySecret();
$credential->getSecurityToken();
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Credentials\Credential\Config;
$config = new Config([
'type' => 'ram_role_arn',
'accessKeyId' => '<access_key_id>',
'accessKeySecret' => '<access_key_secret>',
// Specify the ARN of the RAM role to be assumed. Example: acs:ram::123456789012****:role/adminrole.
'roleArn' => '<role_arn>',
// Specify the name of the role session.
'roleSessionName' => '<role_session_name>',
// Optional. Specify limited permissions for the RAM role. Example: {"Statement": [{"Action": ["*"],"Effect": "Allow","Resource": ["*"]}],"Version":"1"}.
'policy' => '',
// Optional. Specify the expiration of the session
'roleSessionExpiration' => 3600,
]);
$client = new Credential($config);
$credential = $client->getCredential();
$credential->getAccessKeyId();
$credential->getAccessKeySecret();
$credential->getSecurityToken();
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Credentials\Credential\Config;
$config = new Config([
'type' => 'ecs_ram_role',
// Optional. Specify the name of the RAM role of the ECS instance. If you do not specify this parameter, its value is automatically obtained. To reduce the number of requests, we recommend that you specify this parameter.
'roleName' => '<role_name>',
//Optional, whether to forcibly disable IMDSv1, that is, to use IMDSv2 hardening mode, which can be set by the environment variable ALIBABA_CLOUD_IMDSV1_DISABLED
'disableIMDSv1' => true,
]);
$client = new Credential($config);
$credential = $client->getCredential();
$credential->getAccessKeyId();
$credential->getAccessKeySecret();
$credential->getSecurityToken();
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Credentials\Credential\Config;
$config = new Config([
'type' => 'oidc_role_arn',
// Specify the ARN of the OIDC IdP by specifying the ALIBABA_CLOUD_OIDC_PROVIDER_ARN environment variable.
'oidcProviderArn' => '<oidc_provider_arn>',
// Specify the path of the OIDC token file by specifying the ALIBABA_CLOUD_OIDC_TOKEN_FILE environment variable.
'oidcTokenFilePath' => '<oidc_token_file_path>',
// Specify the ARN of the RAM role by specifying the ALIBABA_CLOUD_ROLE_ARN environment variable.
'roleArn' => '<role_arn>',
// Specify the role session name by specifying the ALIBABA_CLOUD_ROLE_SESSION_NAME environment variable.
'roleSessionName' => '<role_session_name>',
// Optional. Specify limited permissions for the RAM role. Example: {"Statement": [{"Action": ["*"],"Effect": "Allow","Resource": ["*"]}],"Version":"1"}.
'policy' => '',
// Optional. Specify the validity period of the session.
'roleSessionExpiration' => 3600,
]);
$client = new Credential($config);
$credential = $client->getCredential();
$credential->getAccessKeyId();
$credential->getAccessKeySecret();
$credential->getSecurityToken();
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Credentials\Credential\Config;
$config = new Config([
'type' => 'credentials_uri',
// Format: http url. `credentialsURI` can be replaced by setting environment variable: ALIBABA_CLOUD_CREDENTIALS_URI
'credentialsURI' => '<credentials_uri>',
]);
$client = new Credential($config);
$credential = $client->getCredential();
$credential->getAccessKeyId();
$credential->getAccessKeySecret();
$credential->getSecurityToken();
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Credentials\Credential\Config;
$config = new Config([
'type' => 'bearer',
'bearerToken' => '<bearer_token>',
]);
$client = new Credential($config);
$credential = $client->getCredential();
$credential->getBearerToken();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.