Exemplo n.º 1
0
        public BasicSessionCredentials GetNewSessionCredentials()
        {
            GetSessionAccessKeyRequest request = new GetSessionAccessKeyRequest();

            request.PublicKeyId     = rsaKeyPairCredential.GetAccessKeyId();
            request.DurationSeconds = (int)sessionDurationSeconds;
            request.Protocol        = ProtocolType.HTTPS;

            GetSessionAccessKeyResponse response = this.stsClient.GetAcsResponse(request);

            return(new BasicSessionCredentials(
                       response.SessionAccesskey.SessionAccessKeyId,
                       response.SessionAccesskey.SessionAccessKeySecert,
                       null,
                       sessionDurationSeconds
                       ));
        }
Exemplo n.º 2
0
        public async Task RsaKeyPairTest()
        {
            Mock <IAlibabaCloudCredentialsProvider> mockProvider = new Mock <IAlibabaCloudCredentialsProvider>();

            mockProvider.Setup(p => p.GetCredentials()).Returns(new RsaKeyPairCredential("publicKeyId", "privateKeySecret", 1000, null));
            mockProvider.Setup(p => p.GetCredentialsAsync()).ReturnsAsync(new RsaKeyPairCredential("publicKeyId", "privateKeySecret", 1000, null));
            RsaKeyPairCredential rsaKeyPairCredential = new RsaKeyPairCredential("publicKeyId", "privateKeySecret", 64090527132000L, mockProvider.Object);

            Assert.Equal("publicKeyId", rsaKeyPairCredential.GetAccessKeyId());
            Assert.Equal("privateKeySecret", rsaKeyPairCredential.GetAccessKeySecret());
            Assert.Null(rsaKeyPairCredential.GetSecurityToken());
            Assert.Equal(64090527132000, rsaKeyPairCredential.GetExpiration());
            Assert.Equal(AuthConstant.RsaKeyPair, rsaKeyPairCredential.GetCredentialType());

            Assert.Equal("publicKeyId", await rsaKeyPairCredential.GetAccessKeyIdAsync());
            Assert.Equal("privateKeySecret", await rsaKeyPairCredential.GetAccessKeySecretAsync());
            Assert.Null(await rsaKeyPairCredential.GetSecurityTokenAsync());
            Assert.Equal(64090527132000, await rsaKeyPairCredential.GetExpirationAsync());
            Assert.Equal(AuthConstant.RsaKeyPair, await rsaKeyPairCredential.GetCredentialTypeAsync());
        }