|  | 
|  | 1 | +[← Examples](0-Examples-EN.md) | Client & Credentials[(中文)](1-Client-CN.md) | [Home →](../../README.md) | 
|  | 2 | +*** | 
|  | 3 | + | 
|  | 4 | +### Using AccessKey call | 
|  | 5 | + | 
|  | 6 | +```java | 
|  | 7 | + | 
|  | 8 | +use AlibabaCloud\Tea\Rpc\Rpc\Config; | 
|  | 9 | + | 
|  | 10 | +$config = new Config(); | 
|  | 11 | +$config->accessKeyId = "<Access-Key-Id>"; | 
|  | 12 | +$config->accessKeySecret = "<Access-Key-Secret>"; | 
|  | 13 | +$client = new ImageSearch($config); | 
|  | 14 | + | 
|  | 15 | +``` | 
|  | 16 | + | 
|  | 17 | +### Use the default credential provider chain | 
|  | 18 | + | 
|  | 19 | +The default credential provider chain looks for available credentials, with following order: | 
|  | 20 | + | 
|  | 21 | +1. Environment Credentials | 
|  | 22 | + | 
|  | 23 | +Look for environment credentials in environment variable. If the `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` environment variables are defined and are not empty, the program will use them to create default credentials. | 
|  | 24 | + | 
|  | 25 | +2. Credentials File | 
|  | 26 | + | 
|  | 27 | +If there is `~/.alibabacloud/credentials` default file (Windows shows `C:\Users\USER_NAME\.alibabacloud\credentials`), the program will automatically create clients with the specified type and name. The default file may not exist, but a parse error throws an exception. The client name is case-insensitive, and if the clients have the same name, the latter will override the former. The specified files can also be loaded indefinitely: `AlibabaCloud::load('/data/credentials', 'vfs://AlibabaCloud/credentials', ...);` This configuration file can be shared between different projects and between different tools. Because it is outside the project and will not be accidentally committed to the version control. Environment variables can be used on Windows to refer to the home directory %UserProfile%. Unix-like systems can use the environment variable $HOME or ~ (tilde). The path to the default file can be modified by defining the `ALIBABA_CLOUD_CREDENTIALS_FILE` environment variable. | 
|  | 28 | + | 
|  | 29 | +```ini | 
|  | 30 | +[default] # Default client | 
|  | 31 | +enable = true # Enable,Enabled by default if this option not present | 
|  | 32 | +type = access_key # Certification type: access_key | 
|  | 33 | +access_key_id = foo # Key | 
|  | 34 | +access_key_secret = bar # Secret | 
|  | 35 | +region_id = cn-hangzhou # Optional,Region | 
|  | 36 | +debug = true # Optional,Debug mode will output the details under CLI | 
|  | 37 | +timeout = 0.2 # Optional,Time-out period. if >1, unit is seconds; if<1, unit will be converted to milliseconds by multiplying 1000 automatically | 
|  | 38 | +connect_Timeout = 0.03 # Optional,Connection timeout, same as timeout | 
|  | 39 | +cert_file = /path/server.pem # Optional,Certification file | 
|  | 40 | +cert_password = password # Optional,Certification password, can be empty if no password | 
|  | 41 | +proxy = tcp://localhost:8125 # Optional,General proxy | 
|  | 42 | +proxy_http = tcp://localhost:8125 # Optional,HTTP proxy | 
|  | 43 | +proxy_https = tcp://localhost:9124 # Optional,HTTPS proxy | 
|  | 44 | +proxy_no = .mit.edu,foo.com # Optional,Ignored Domain Name by proxy | 
|  | 45 | + | 
|  | 46 | +[client1] # Client that is named as `client1` | 
|  | 47 | +type = ecs_ram_role # Certification type: ecs_ram_role | 
|  | 48 | +role_name = EcsRamRoleTest # Role Name | 
|  | 49 | +#..................................# As above, other configurations ignored. | 
|  | 50 | + | 
|  | 51 | +[client2] # Client that is named as `client2`  | 
|  | 52 | +enable = false # Disable | 
|  | 53 | +type = ram_role_arn # Certification type: ram_role_arn | 
|  | 54 | +access_key_id = foo | 
|  | 55 | +access_key_secret = bar | 
|  | 56 | +role_arn = role_arn | 
|  | 57 | +role_session_name = session_name | 
|  | 58 | +#..................................# As above, other configurations ignored. | 
|  | 59 | + | 
|  | 60 | +[client3] # Client that is named as `client3` | 
|  | 61 | +type = rsa_key_pair # Certification type: rsa_key_pair | 
|  | 62 | +public_key_id = publicKeyId # Public Key ID | 
|  | 63 | +private_key_file = /your/pk.pem # Private Key file | 
|  | 64 | +#..................................# As above, other configurations ignored. | 
|  | 65 | +``` | 
|  | 66 | + | 
|  | 67 | +3. Instance RAM Role | 
|  | 68 | + | 
|  | 69 | +If the environment variable `ALIBABA_CLOUD_ECS_METADATA` is defined and not empty, the program will take the value of the environment variable as the role name and request `http://100.100.100.200/latest/meta-data/ram/security-credentials/` to get the temporary Security credentials, then create a default client. | 
|  | 70 | + | 
|  | 71 | +*** | 
|  | 72 | +[← Examples](0-Examples-EN.md) | Client & Credentials[(中文)](1-Client-CN.md) | [Home →](../../README.md) | 
0 commit comments