Para enviar solicitudes a Object Storage Service (OSS) con el kit de desarrollo de software (SDK) de C#, debe configurar las credenciales de acceso. Los servicios de Alibaba Cloud utilizan estas credenciales para verificar su identidad y sus permisos de acceso. Puede proporcionar las credenciales de diversas maneras, según los requisitos de autenticación y autorización de su escenario.
Notas
Para consultar información sobre las regiones y los endpoints que admite OSS, consulte Regions and endpoints.
Para crear un par de AccessKey para un usuario de Resource Access Management (RAM), consulte Create an AccessKey pair.
Elegir un proveedor de credenciales
OSS admite varias formas de inicializar un proveedor de credenciales. Elija el método de inicialización adecuado según sus requisitos de autenticación y autorización.
|
Método de inicialización del proveedor de credenciales |
Escenarios |
¿Requiere un par de AccessKey o un token de Security Token Service (STS) existente? |
Tipo de credencial subyacente |
Validez de la credencial |
Método de rotación o renovación de la credencial |
|
Aplicaciones que se ejecutan en un entorno seguro y estable, sin vulnerabilidad ante ataques externos. Estas aplicaciones necesitan acceso prolongado a los servicios de Alibaba Cloud y no requieren una rotación frecuente de credenciales. |
Sí |
Par de AccessKey |
A largo plazo |
Rotación manual |
|
|
Aplicaciones que se ejecutan en un entorno no confiable. Este método le permite controlar el periodo de validez y los permisos del acceso. |
Sí |
Token de STS |
Temporal |
Renovación manual |
|
|
Aplicaciones que requieren acceso autorizado a los servicios de Alibaba Cloud, como el acceso entre cuentas. |
Sí |
Token de STS |
Temporal |
Renovación automática |
|
|
Aplicaciones que se ejecutan en instancias de ECS, instancias de ECI o nodos de trabajo de Container Service for Kubernetes en Alibaba Cloud. |
No |
Token de STS |
Temporal |
Renovación automática |
|
|
Aplicaciones no confiables que se ejecutan en nodos de trabajo de Container Service for Kubernetes. |
No |
Token de STS |
Temporal |
Renovación automática |
|
|
Aplicaciones que necesitan obtener credenciales de acceso desde un sistema externo. |
No |
Token de STS |
Temporal |
Renovación automática |
|
|
Si ninguno de los métodos anteriores cumple con sus necesidades, puede personalizar la forma de obtener las credenciales. |
Personalizado |
Personalizado |
Personalizado |
Personalizado |
Ejemplos comunes de configuración
Uso del AK de un usuario de RAM
Si su aplicación se despliega en un entorno seguro y estable, requiere acceso prolongado a OSS y no permite una rotación frecuente de credenciales, puede inicializar el proveedor de credenciales con el par de AccessKey (AccessKey ID y AccessKey secret) de una cuenta de Alibaba Cloud o de un usuario de RAM. Sin embargo, este método exige mantener manualmente el par de AccessKey, lo cual incrementa los riesgos de seguridad y la complejidad del mantenimiento. Para obtener un par de AccessKey, consulte CreateAccessKey - Create an AccessKey pair for an Alibaba Cloud account or a RAM user.
Variables de entorno
Una cuenta de Alibaba Cloud tiene permisos completos sobre todos los recursos. Si se filtra un par de AccessKey, el sistema queda expuesto a riesgos de seguridad importantes. Se recomienda no utilizar el par de AccessKey de una cuenta de Alibaba Cloud. En su lugar, utilice el par de AccessKey de un usuario de RAM con los permisos mínimos necesarios.
-
Establezca las variables de entorno mediante un par de AccessKey.
Mac OS X, Linux o Unix
export ALIBABA_CLOUD_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>Windows
set ALIBABA_CLOUD_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID> set ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET> -
Pase la información de las credenciales mediante variables de entorno.
using Aliyun.OSS; using Aliyun.OSS.Common; using Aliyun.OSS.Common.Authentication; // Obtain access credentials from environment variables. Before you run this code, make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set. var accessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"); var accessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); var credentialsProvider = new DefaultCredentialsProvider(new DefaultCredentials(accessKeyId, accessKeySecret, "")); // Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com"; // Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou. const string region = "cn-hangzhou"; var conf = new ClientConfiguration(); var client = new OssClient(endpoint, credentialsProvider, conf); client.SetRegion(region);
Credenciales estáticas
A continuación se muestra un ejemplo de código que indica cómo codificar de forma fija las credenciales de acceso y establecer explícitamente el par de AccessKey que se va a utilizar.
No inserte credenciales de acceso directamente en las aplicaciones de un entorno de producción. Este método es exclusivo para pruebas.
using Aliyun.OSS;
using Aliyun.OSS.Common;
using Aliyun.OSS.Common.Authentication;
// Replace the sample values with your actual AccessKey ID and AccessKey secret.
var accessKeyId = "LTAI5tQQx1DWEYK7********" ;
var accessKeySecret = "s5LkMqKmmKbt3zjs7MNJTj********" ;
var credentialsProvider = new DefaultCredentialsProvider(new DefaultCredentials(accessKeyId, accessKeySecret, ""));
// Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";
var conf = new ClientConfiguration();
var client = new OssClient(endpoint, credentialsProvider, conf);
client.SetRegion(region);
Uso de una credencial de acceso temporal de STS
Si su aplicación necesita acceso temporal a OSS, puede inicializar el proveedor de credenciales con una credencial de identidad temporal (AccessKey ID, AccessKey secret y token de seguridad) obtenida de Security Token Service (STS). No obstante, este método requiere mantener manualmente el token de STS, lo que aumenta los riesgos de seguridad y la complejidad del mantenimiento. Además, si necesita acceder a OSS de forma temporal en varias ocasiones, deberá renovar el token de STS manualmente.
Para obtener rápidamente una credencial de acceso temporal de STS mediante una llamada a una operación de OpenAPI, consulte AssumeRole - Obtain a temporary identity credential to assume a role.
Para obtener una credencial de acceso temporal de STS con un SDK, consulte Use an STS temporary access credential to access OSS.
Debe especificar un tiempo de caducidad al generar un token de STS. El token deja de ser válido automáticamente cuando caduca y no se puede volver a utilizar.
Para consultar la lista de endpoints de STS, consulte Endpoints.
Variables de entorno
-
Establezca las variables de entorno mediante una credencial de identidad temporal.
Mac OS X, Linux o Unix
export ALIBABA_CLOUD_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET> export ALIBABA_CLOUD_SECURITY_TOKEN=<ALIBABA_CLOUD_SECURITY_TOKEN>Windows
set OSS_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID> set OSS_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET> set OSS_SESSION_TOKEN=<ALIBABA_CLOUD_SECURITY_TOKEN> -
Pase la información de las credenciales mediante variables de entorno.
using Aliyun.OSS; using Aliyun.OSS.Common; using Aliyun.OSS.Common.Authentication; // Obtain access credentials from environment variables. Before you run this code, make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID, ALIBABA_CLOUD_ACCESS_KEY_SECRET, and ALIBABA_CLOUD_SECURITY_TOKEN environment variables are set. var accessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"); var accessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); var token = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_SECURITY_TOKEN"); var credentialsProvider = new DefaultCredentialsProvider(new DefaultCredentials(accessKeyId, accessKeySecret, token)); // Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com"; // Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou. const string region = "cn-hangzhou"; var conf = new ClientConfiguration(); var client = new OssClient(endpoint, credentialsProvider, conf); client.SetRegion(region);
Credenciales estáticas
Puede codificar de forma fija las credenciales en su aplicación para establecer explícitamente el par de AccessKey temporal que se va a utilizar.
using Aliyun.OSS;
using Aliyun.OSS.Common;
using Aliyun.OSS.Common.Authentication;
// Replace the sample values with your actual temporary AccessKey ID, AccessKey secret, and security token.
var accessKeyId = "STS.NTZdStF79CVRTQuWCfXTT****";
var accessKeySecret = "5rm8PfEiK8enp56zzAMX4RbZUraoKbWXvCf1xAuT****"
var token = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_SECURITY_TOKEN");
var credentialsProvider = new DefaultCredentialsProvider(new DefaultCredentials(accessKeyId, accessKeySecret, token));
// Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";
var conf = new ClientConfiguration();
var client = new OssClient(endpoint, credentialsProvider, conf);
client.SetRegion(region);
Más ejemplos de configuración por escenario
Uso de RAMRoleARN
Si su aplicación requiere acceso autorizado a OSS, como el acceso entre cuentas, puede inicializar el proveedor de credenciales mediante un RAMRoleARN. Este método utiliza un token de STS como credencial subyacente. Al especificar el nombre de recurso de Alibaba Cloud (ARN) de un rol de RAM, la herramienta de credenciales recupera un token de STS del servicio correspondiente y lo renueva automáticamente antes de que caduque. También puede asignar un valor a policy para restringir el rol de RAM a un conjunto menor de permisos.
Una cuenta de Alibaba Cloud tiene permisos completos sobre todos los recursos. Si se filtra un par de AccessKey, el sistema queda expuesto a riesgos de seguridad importantes. Se recomienda no utilizar el par de AccessKey de una cuenta de Alibaba Cloud. En su lugar, utilice el par de AccessKey de un usuario de RAM con los permisos mínimos necesarios.
Para obtener más información sobre cómo crear un par de AccessKey para un usuario de RAM, consulte Create an AccessKey pair. El AccessKey ID y el AccessKey secret de un usuario de RAM solo se muestran en el momento de su creación, por lo que debe guardarlos de inmediato. Si olvida el AccessKey secret, tendrá que crear un nuevo par de AccessKey para sustituirlo.
Para obtener un RAMRoleARN, consulte CreateRole - Create a role.
Instale la biblioteca de credenciales de Alibaba Cloud. Para obtener más información, consulte Manage access credentials.
-
Configure las credenciales de acceso.
using Aliyun.OSS; using Aliyun.OSS.Common; using Aliyun.OSS.Common.Authentication; class CredentialsProviderWrapper : ICredentialsProvider { private Aliyun.Credentials.Client client; public CredentialsProviderWrapper(Aliyun.Credentials.Client client) { this.client = client; } public ICredentials GetCredentials() { var accessKeyId = client.GetAccessKeyId(); var accessKeySecret = client.GetAccessKeySecret(); var token = client.GetSecurityToken(); return new DefaultCredentials(accessKeyId, accessKeySecret, token); } public void SetCredentials(ICredentials creds) { } }; var config = new Aliyun.Credentials.Models.Config() { Type = "ram_role_arn", AccessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), // By default, the following operations use parameter values that are directly entered. You can also add environment variables and use Environment.GetEnvironmentVariable("<variable_name>") to get the corresponding parameters. // The ARN of the RAM role to assume. Example: acs:ram::123456789012****:role/adminrole RoleArn = "<RoleArn>", // The default environment variable for RoleArn is ALIBABA_CLOUD_ROLE_ARN. // The role session name. RoleSessionName = "<RoleSessionName>", // The default environment variable for RoleSessionName is ALIBABA_CLOUD_ROLE_SESSION_NAME. }; var credentialsClient = new Aliyun.Credentials.Client(config); var credentialsProvider = new CredentialsProviderWrapper(credentialsClient); // Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com"; // Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou. const string region = "cn-hangzhou"; var conf = new ClientConfiguration(); var client = new OssClient(endpoint, credentialsProvider, conf); client.SetRegion(region);
Uso de un rol de RAM de ECS
Si su aplicación se ejecuta en una instancia de Elastic Compute Service (ECS), en una instancia de Elastic Container Instance (ECI) o en un nodo de trabajo de Container Service for Kubernetes, se recomienda utilizar un ECSRAMRole para inicializar el proveedor de credenciales. Este método emplea un token de STS como credencial subyacente. Un ECSRAMRole le permite asociar un rol con una instancia de ECS, una instancia de ECI o un nodo de trabajo de Container Service for Kubernetes. De esta manera, el token de STS se renueva automáticamente dentro de la instancia. Este método no requiere proporcionar un par de AccessKey ni un token de STS, lo que elimina los riesgos asociados con su mantenimiento manual. Para obtener un ECSRAMRole, consulte CreateRole - Create a role.
Instale la biblioteca de credenciales de Alibaba Cloud. Para obtener más información, consulte Manage access credentials.
Configure un ECSRAMRole como credencial de acceso.
using Aliyun.OSS;
using Aliyun.OSS.Common;
using Aliyun.OSS.Common.Authentication;
class CredentialsProviderWrapper : ICredentialsProvider
{
private Aliyun.Credentials.Client client;
public CredentialsProviderWrapper(Aliyun.Credentials.Client client)
{
this.client = client;
}
public ICredentials GetCredentials()
{
var accessKeyId = client.GetAccessKeyId();
var accessKeySecret = client.GetAccessKeySecret();
var token = client.GetSecurityToken();
return new DefaultCredentials(accessKeyId, accessKeySecret, token);
}
public void SetCredentials(ICredentials creds)
{
}
};
var config = new Aliyun.Credentials.Models.Config()
{
Type = "ecs_ram_role",
// Optional. The name of the ECS RAM role. If you do not specify this parameter, the role name is automatically obtained. We recommend that you specify this parameter to reduce the number of requests.
RoleName = "<RoleName>"
};
var credentialsClient = new Aliyun.Credentials.Client(config);
var credentialsProvider = new CredentialsProviderWrapper(credentialsClient);
// Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";
var conf = new ClientConfiguration();
var client = new OssClient(endpoint, credentialsProvider, conf);
client.SetRegion(region);
Uso de OIDCRoleARN
Después de configurar un rol de RAM para los nodos de trabajo en Container Service for Kubernetes, las aplicaciones ubicadas en pods de esos nodos pueden recuperar el token de STS del rol asociado mediante el servicio global de metadatos, de forma similar a las aplicaciones desplegadas en ECS. Sin embargo, si despliega aplicaciones no confiables en el clúster de contenedores (por ejemplo, aplicaciones enviadas por sus clientes cuyo código usted no puede ver), es probable que no desee que recuperen el token de STS del rol de RAM de la instancia asociado a los nodos de trabajo a través del servicio global de metadatos. Para evitar riesgos de seguridad en sus recursos en la nube y permitir que estas aplicaciones no confiables recuperen de forma segura los tokens de STS necesarios, utilice la función RAM Roles for Service Accounts (RRSA). Así logrará minimizar los permisos a nivel de aplicación. Este método utiliza un token de STS como credencial subyacente. Un clúster de contenedores de Alibaba Cloud crea y monta el archivo de token de OpenID Connect (OIDC) de la cuenta de servicio correspondiente para distintos pods de aplicaciones, e inyecta la información de configuración relevante en las variables de entorno. La herramienta de credenciales recupera dicha información de las variables de entorno y llama a la operación AssumeRoleWithOIDC de STS para intercambiar el token de OIDC por un token de STS del rol vinculado. Este método no requiere proporcionar un par de AccessKey ni un token de STS, lo que elimina los riesgos asociados con su mantenimiento manual. Para obtener más información, consulte Isolate pod permissions based on RRSA.
Se inyectan las siguientes variables de entorno:
ALIBABA_CLOUD_ROLE_ARN: el ARN del rol de RAM.
ALIBABA_CLOUD_OIDC_PROVIDER_ARN: el ARN del proveedor de OIDC.
ALIBABA_CLOUD_OIDC_TOKEN_FILE: la ruta al archivo del token de OIDC.
Configure un OIDCRoleArn como credencial de acceso.
using Aliyun.OSS;
using Aliyun.OSS.Common;
using Aliyun.OSS.Common.Authentication;
class CredentialsProviderWrapper : ICredentialsProvider
{
private Aliyun.Credentials.Client client;
public CredentialsProviderWrapper(Aliyun.Credentials.Client client)
{
this.client = client;
}
public ICredentials GetCredentials()
{
var accessKeyId = client.GetAccessKeyId();
var accessKeySecret = client.GetAccessKeySecret();
var token = client.GetSecurityToken();
return new DefaultCredentials(accessKeyId, accessKeySecret, token);
}
public void SetCredentials(ICredentials creds)
{}
};
var config = new Aliyun.Credentials.Models.Config()
{
Type = "oidc_role_arn",
// The ARN of the RAM role. You can set RoleArn using the ALIBABA_CLOUD_ROLE_ARN environment variable.
RoleArn = "<RoleArn>",
// The ARN of the OIDC provider. You can set OidcProviderArn using the ALIBABA_CLOUD_OIDC_PROVIDER_ARN environment variable.
OIDCProviderArn = "<OidcProviderArn>",
// The path to the OIDC token file. You can set OidcTokenFilePath using the ALIBABA_CLOUD_OIDC_TOKEN_FILE environment variable.
OIDCTokenFilePath = "<OidcTokenFilePath>",
// The role session name. You can set RoleSessionName using the ALIBABA_CLOUD_ROLE_SESSION_NAME environment variable.
RoleSessionName = "<RoleSessionName>",
// Optional. A more restrictive access policy. Example: {"Statement": [{"Action": ["*"],"Effect": "Allow","Resource": ["*"]}],"Version":"1"}
Policy = "<Policy>",
RoleSessionExpiration = 3600
};
var credentialsClient = new Aliyun.Credentials.Client(config);
var credentialsProvider = new CredentialsProviderWrapper(credentialsClient);
// Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";
var conf = new ClientConfiguration();
var client = new OssClient(endpoint, credentialsProvider, conf);
client.SetRegion(region);
Uso de CredentialsURI
Si su aplicación necesita recuperar credenciales de Alibaba Cloud desde un sistema externo para lograr una gestión flexible de credenciales y un acceso sin claves, puede inicializar el proveedor de credenciales mediante un CredentialsURI. Este método utiliza un token de STS como credencial subyacente. La herramienta de credenciales recupera un token de STS desde la URI que usted proporciona para completar la inicialización del cliente de credenciales. Este método no requiere proporcionar un par de AccessKey ni un token de STS, lo que elimina los riesgos asociados con su mantenimiento manual. El servicio de backend que proporciona la respuesta de CredentialsURI debe implementar una lógica de renovación automática del token de STS para garantizar que su aplicación siempre pueda recuperar credenciales válidas.
using Aliyun.OSS;
using Aliyun.OSS.Common;
using Aliyun.OSS.Common.Authentication;
class CredentialsProviderWrapper : ICredentialsProvider
{
private Aliyun.Credentials.Client client;
public CredentialsProviderWrapper(Aliyun.Credentials.Client client)
{
this.client = client;
}
public ICredentials GetCredentials()
{
var accessKeyId = client.GetAccessKeyId();
var accessKeySecret = client.GetAccessKeySecret();
var token = client.GetSecurityToken();
return new DefaultCredentials(accessKeyId, accessKeySecret, token);
}
public void SetCredentials(ICredentials creds)
{}
};
var config = new Aliyun.Credentials.Models.Config()
{
// The credential type.
Type = "credentials_uri",
// The URI from which to obtain credentials. The format is http://local_or_remote_uri/. You can set CredentialsURI using the ALIBABA_CLOUD_CREDENTIALS_URI environment variable.
CredentialsURI = "<CredentialsURI>"
};
var credentialsClient = new Aliyun.Credentials.Client(config);
var credentialsProvider = new CredentialsProviderWrapper(credentialsClient);
// Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";
var conf = new ClientConfiguration();
var client = new OssClient(endpoint, credentialsProvider, conf);
client.SetRegion(region);
Uso de una credencial de acceso personalizada
Si ninguno de los métodos de configuración anteriores satisface sus necesidades, puede implementar la interfaz Credential Providers para personalizar la forma en que se proporcionan las credenciales.
using Aliyun.OSS;
using Aliyun.OSS.Common;
using Aliyun.OSS.Common.Authentication;
class CustomCredentialsProvider : ICredentialsProvider
{
public CustomCredentialsProvider()
{
}
public ICredentials GetCredentials()
{
// TODO
// Custom method to obtain access credentials.
string accessKeyId;
string accessKeySecret;
//string token;
// Return long-term credentials: access_key_id, access_key_secret.
return new DefaultCredentials(accessKeyId, accessKeySecret, "");
// Return temporary credentials: access_key_id, access_key_secret, token.
// For temporary credentials, you must refresh the credentials based on their expiration time.
// return new DefaultCredentials(accessKeyId, accessKeySecret, token);
}
public void SetCredentials(ICredentials creds)
{
}
};
var credentialsProvider = new CustomCredentialsProvider();
// Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
const string endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";
var conf = new ClientConfiguration();
var client = new OssClient(endpoint, credentialsProvider, conf);
client.SetRegion(region);