示例#1
0
 public TestTask(String name, String messageType, String queueName, IAcsClient acsClient)
 {
     this.name        = name;
     this.messageType = messageType;
     this.queueName   = queueName;
     this.acsClient   = acsClient;
 }
示例#2
0
        public AliyunSmsClient()
        {
            var aliyunSmsSettting = AliyunSmsHelper.GetSettingsFunc();

            if (aliyunSmsSettting == null)
            {
                throw new SmsException("请配置短信服务相关配置!");
            }
            if (string.IsNullOrWhiteSpace(aliyunSmsSettting.SignName))
            {
                throw new SmsException("签名不能为空!");
            }
            try
            {
                AliyunSmsHelper.LoggerAction("Debug", "SmsSettings:" + JsonConvert.SerializeObject(aliyunSmsSettting));
                this.AliyunSmsSettting = aliyunSmsSettting;
                var product         = aliyunSmsSettting.Product;         //短信API产品名称(短信产品名固定,无需修改)
                var domain          = aliyunSmsSettting.Domain;          //短信API产品域名(接口地址固定,无需修改)
                var accessKeyId     = aliyunSmsSettting.AccessKeyId;     //你的accessKeyId,参考本文档步骤2
                var accessKeySecret = aliyunSmsSettting.AccessKeySecret; //你的accessKeySecret,参考本文档步骤2

                var profile = DefaultProfile.GetProfile(aliyunSmsSettting.RegionId, accessKeyId, accessKeySecret);
                DefaultProfile.AddEndpoint(aliyunSmsSettting.EndpointName, aliyunSmsSettting.RegionId, product, domain);
                AcsClient = new DefaultAcsClient(profile);
                AliyunSmsHelper.LoggerAction("Debug", "已创建AcsClient。");
            }
            catch (Exception ex)
            {
                AliyunSmsHelper.LoggerAction("Error", ex.ToString());
                throw new SmsException("配置出错,请检查配置!");
            }
        }
        private SMSService()
        {
            IClientProfile profile = DefaultProfile.GetProfile(
                _configuration.RegionId, _configuration.AccessKeyId, _configuration.Secret);

            _client = new DefaultAcsClient(profile);
        }
示例#4
0
 public MainTask(String name, String messageType, String queueName, IAcsClient acsClient)
 {
     this.Name        = name;
     this.MessageType = messageType;
     this.QueueName   = queueName;
     this.AcsClient   = acsClient;
 }
示例#5
0
 public static Task <HttpResponse> DoActionAsync <T>(this IAcsClient client, AcsRequest <T> request,
                                                     bool autoRetry, int maxRetryNumber,
                                                     string regionId, Credential credential,
                                                     Signer signer, FormatType?format,
                                                     List <Endpoint> endpoints) where T : AcsResponse
 {
     return(client.DoActionAsync(request, autoRetry, maxRetryNumber, regionId, credential, signer, format, endpoints, default(CancellationToken)));
 }
示例#6
0
        public DDNS(string accessKeyId, string accessKeySecret)
        {
            IClientProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret);

            // 若报Can not find endpoint to access异常,请添加以下此行代码
            // DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Alidns", "alidns.aliyuncs.com");
            client = new DefaultAcsClient(profile);
        }
示例#7
0
 public STSAssumeRoleSessionCredentialsProvider(AlibabaCloudCredentialsProvider longLivedCredentialsProvider,
                                                String roleArn, IClientProfile clientProfile)
 {
     this.roleArn                    = roleArn;
     this.roleSessionName            = GetNewRoleSessionName();
     this.stsClient                  = new DefaultAcsClient(clientProfile, longLivedCredentialsProvider);
     this.roleSessionDurationSeconds = DEFAULT_DURATION_SECONDS;
 }
示例#8
0
 public ctEMail()
 {
     appid   = ConfigurationManager.AppSettings["aliaccount"];
     secret  = ConfigurationManager.AppSettings["alipassword"];
     myemail = ConfigurationManager.AppSettings["myemail"];
     profile = DefaultProfile.GetProfile("cn-hangzhou", appid, secret);
     client  = new DefaultAcsClient(profile);
 }
        public STSAssumeRoleSessionCredentialsProvider(AlibabaCloudCredentials longLivedCredentials, string roleArn, IAcsClient client)
        {
            AlibabaCloudCredentialsProvider longLivedCredentialsProvider = new StaticCredentialsProvider(longLivedCredentials);

            this.roleArn                    = roleArn;
            this.roleSessionName            = GetNewRoleSessionName();
            this.stsClient                  = client;
            this.roleSessionDurationSeconds = DEFAULT_DURATION_SECONDS;
        }
示例#10
0
        public AliyunSmsService(IOptions <AliyunSmsOptions> options, ILogger <AliyunSmsService> logger, ICache cache)
        {
            _options = options.Value;
            _logger  = logger;
            _cache   = cache;

            AliyunUtil.AddEndpoint(AliyunProductNames.SMS, _options.RegionId, _options.Endpoint);
            _client = AliyunUtil.CreateAcsClient(_options.RegionId, _options.AccessKeyId, _options.AccessKeySecret);
        }
 public STSAssumeRoleSessionCredentialsProvider(
     AlibabaCloudCredentialsProvider longLivedCredentialsProvider,
     string roleArn,
     IClientProfile clientProfile)
 {
     this.roleArn    = roleArn;
     roleSessionName = GetNewRoleSessionName();
     stsClient       = new DefaultAcsClient(clientProfile, longLivedCredentialsProvider);
 }
示例#12
0
        public QueryTokenForMnsQueueResponse.MessageTokenDTO_ GetTokenByMessageType(IAcsClient acsClient, String messageType)
        {
            QueryTokenForMnsQueueRequest request = new QueryTokenForMnsQueueRequest();

            request.MessageType = messageType;
            QueryTokenForMnsQueueResponse queryTokenForMnsQueueResponse = acsClient.GetAcsResponse(request);

            QueryTokenForMnsQueueResponse.MessageTokenDTO_ token = queryTokenForMnsQueueResponse.MessageTokenDTO;
            return(token);
        }
示例#13
0
        public STSAssumeRoleSessionCredentialsProvider(
            AlibabaCloudCredentials longLivedCredentials,
            string roleArn,
            IAcsClient client)
        {
            AlibabaCloudCredentialsProvider longLivedCredentialsProvider = new StaticCredentialsProvider(longLivedCredentials);

            this.roleArn    = roleArn;
            roleSessionName = GetNewRoleSessionName();
            stsClient       = client;
        }
 public STSAssumeRoleSessionCredentialsProvider(
     string roleArn,
     string policy,
     IAcsClient client
     )
 {
     this.roleArn    = roleArn;
     this.policy     = policy;
     roleSessionName = GetNewRoleSessionName();
     stsClient       = client;
 }
        private static ProductDomain GetProductDomainByLocation(String regionId,
                                                                String product, IAcsClient acsClient)
        {
            DescribeEndpointRequest describeEndpointRequest = new DescribeEndpointRequest();

            describeEndpointRequest.RegionId = regionId;
            describeEndpointRequest.SetService(product.ToLower());
            //DescribeEndpointResponse describeEndpointResponse = acsClient.getAcsResponse(describeEndpointRequest);
            //ProductDomain productDomain = new ProductDomain(product, describeEndpointResponse.Endpoint);
            //return productDomain;
            return(null);
        }
示例#16
0
        private void Init()
        {
            var profile = DefaultProfile.GetProfile(Options.RegionId, Options.AccessKeyId, Options.AccessKeySecret);

            client  = new DefaultAcsClient(profile);
            request = new DescribeDomainRecordsRequest();

            //request.Url = "http://domain.aliyuncs.com/";
            request.DomainName  = Options.DomainName;
            request.TypeKeyWord = Options.DomainType;
            //request.ActionName = "DescribeDomainRecords";
        }
示例#17
0
        public LowTrustSharePointContext(
            IHttpContextAccessor httpContextAccessor,
            ISharePointClient sharePointClient,
            IAcsClient acsClient,
            IOptions <LowTrustSharePointOptions> options) : base(httpContextAccessor)
        {
            _options = options.Value ?? throw new ArgumentNullException(nameof(LowTrustSharePointOptions));

            _sharePointClient = sharePointClient;
            _acsClient        = acsClient;

            _tokenHandler = new JwtSecurityTokenHandler();
        }
示例#18
0
        public STSAssumeRoleSessionCredentialsProvider(
            AlibabaCloudCredentials longLivedCredentials,
            string roleArn,
            string policy,
            IClientProfile profile
            )
        {
            AlibabaCloudCredentialsProvider longLivedCredentialsProvider = new StaticCredentialsProvider(longLivedCredentials);

            this.roleArn    = roleArn;
            this.policy     = policy;
            roleSessionName = GetNewRoleSessionName();
            stsClient       = new DefaultAcsClient(profile, longLivedCredentialsProvider);
        }
示例#19
0
        public ActionResult TestCode(string username, string password)
        {
            IAcsClient client = null;



            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", ConstString.KeyId, ConstString.KeySecret);

            client = new DefaultAcsClient(profile);
            DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", "Jaq", "jaq.aliyuncs.com");


            AfsCheckRequest request = new AfsCheckRequest();

            request.Platform = 3;                            //必填参数,请求来源: 1:Android端; 2:iOS端; 3:PC端及其他
            request.Session  = Request.Params["csessionid"]; // 必填参数,从前端获取,不可更改
            request.Sig      = Request.Params["sig"];        // 必填参数,从前端获取,不可更改
            request.Token    = Request.Params["token"];      // 必填参数,从前端获取,不可更改
            request.Scene    = Request.Params["scene"];      // 必填参数,从前端获取,不可更改

            ResultView <string> result = new ResultView <string>();

            try
            {
                AfsCheckResponse response = client.GetAcsResponse(request);
                if (response.ErrorCode == null || response.ErrorCode.Value == 0)
                {
                    //写正常业务逻辑

                    result = (new ResultView <string> {
                        Flag = true, Message = "登录成功"
                    });
                }
                else
                {
                    result = (new ResultView <string> {
                        Flag = false, Message = "Error:" + response.ErrorMsg
                    });
                }
            }
            catch (Exception e)
            {
                //验证不通过,给出错误提示
                return(Json(new ResultView <string> {
                    Flag = false, Message = "验证码错误" + e.Message
                }));
            }
            return(Json(result));
        }
示例#20
0
        public void WithSTSClient()
        {
            var mock = new Mock <AlibabaCloudCredentials>();
            AlibabaCloudCredentials longLivedCredentials = mock.Object;
            string         roleArn = "roleArn";
            IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "accessKeySecret");
            STSAssumeRoleSessionCredentialsProvider instance = new STSAssumeRoleSessionCredentialsProvider(longLivedCredentials, roleArn, profile);

            var        mockClient = new Mock <IAcsClient>();
            IAcsClient client     = mockClient.Object;

            instance.WithSTSClient(client); // 方法回调 STSAssumeRoleSessionCredentialsProvider 实例

            Assert.IsType <STSAssumeRoleSessionCredentialsProvider>(instance);
        }
示例#21
0
        public AliyunStsService(IOptions <AliyunStsOptions> options, ILogger <AliyunStsService> logger)
        {
            _options = options.Value;
            _logger  = logger;

            AliyunUtil.AddEndpoint(AliyunProductNames.STS, "", _options.Endpoint);
            _acsClient = AliyunUtil.CreateAcsClient("", _options.AccessKeyId, _options.AccessKeySecret);

            foreach (AssumedRole assumedRole in _options.AssumedRoles)
            {
                foreach (string resource in assumedRole.Resources)
                {
                    _resourceAssumedRoleDict[resource] = assumedRole;
                }
            }
        }
示例#22
0
        public DomainRecord(DomainRecordOptions options)
        {
            Options = options;
            var profile = DefaultProfile.GetProfile(Options.RegionId, Options.AccessKeyId, Options.AccessKeySecret);

            client  = new DefaultAcsClient(profile);
            request = new DescribeDomainRecordsRequest();

            //request.Url = "http://domain.aliyuncs.com/";
            request.DomainName  = Options.DomainName;
            request.TypeKeyWord = Options.DomainType;
            //request.ActionName = "DescribeDomainRecords";

            var response = client.GetAcsResponse(request);

            describeDomainRecords_Records = response.DomainRecords;
        }
 public static ProductDomain FindProductDomain(String regionId, String product,
         List<Endpoint> endpoints, IAcsClient acsClient)
 {
     if (null == regionId || null == product || null == endpoints)
     {
         return null;
     }
     foreach (Endpoint endpoint in endpoints)
     {
         if (endpoint.RegionIds.Contains(regionId))
         {
             ProductDomain domain = FindProductDomainByProduct(endpoint.ProductDomains, product);
             return domain;
         }
     }
     if ("Location".Equals(product))
     {
         return new ProductDomain("Location", "location.aliyuncs.com");
     }
     return GetEndpointByLocation(regionId, product, endpoints, acsClient);
 }
示例#24
0
 public static ProductDomain FindProductDomain(String regionId, String product,
                                               List <Endpoint> endpoints, IAcsClient acsClient)
 {
     if (null == regionId || null == product || null == endpoints)
     {
         return(null);
     }
     foreach (Endpoint endpoint in endpoints)
     {
         if (endpoint.RegionIds.Contains(regionId))
         {
             ProductDomain domain = FindProductDomainByProduct(endpoint.ProductDomains, product);
             return(domain);
         }
     }
     if ("Location".Equals(product))
     {
         return(new ProductDomain("Location", "location.aliyuncs.com"));
     }
     return(null);
 }
示例#25
0
 public STSAssumeRoleSessionCredentialsProvider WithSTSClient(IAcsClient client)
 {
     this.stsClient = client;
     return(this);
 }
示例#26
0
 public RsaKeyPairCredentialProvider WithSTSClient(IAcsClient client)
 {
     this.stsClient = client;
     return(this);
 }
示例#27
0
 public RsaKeyPairCredentialProvider(RsaKeyPairCredential rsaKeyPairCredential, IClientProfile profile)
 {
     this.rsaKeyPairCredential = rsaKeyPairCredential;
     this.stsClient            = new DefaultAcsClient(profile, rsaKeyPairCredential);
 }
示例#28
0
 public void WithSTSClient(IAcsClient client)
 {
     stsClient = client;
 }
示例#29
0
 public RsaKeyPairCredentialProvider(KeyPairCredentials rsaKeyPairCredential, IAcsClient stsClient)
 {
     this.rsaKeyPairCredential = rsaKeyPairCredential;
     this.stsClient            = stsClient;
 }
        private static ProductDomain GetEndpointByLocation(string regionId, string product,
                                                           List <Endpoint> endpoints, IAcsClient acsClient)
        {
            var productDomain = GetProductDomainByLocation(regionId, product, acsClient);

            foreach (var endpoint in endpoints)
            {
                if (endpoint.RegionIds.Contains(regionId))
                {
                    endpoint.ProductDomains.Add(productDomain);
                    return(productDomain);
                }
            }

            ISet <string> regionIds = new HashSet <string>();

            regionIds.Add(regionId);
            var productDomains = new List <ProductDomain>
            {
                productDomain
            };

            endpoints.Add(new Endpoint(regionId, regionIds, productDomains));
            return(productDomain);
        }
示例#31
0
 // 初始化环境
 private static void InitData()
 {
     acsClient = InitAcsClient(regionIdForPop, accessId, accessSecret, productName, domainForPop);
 }
        private static ProductDomain GetEndpointByLocation(String regionId, String product,
                List<Endpoint> endpoints, IAcsClient acsClient)
        {
            ProductDomain productDomain = GetProductDomainByLocation(regionId, product, acsClient);

            foreach (Endpoint endpoint in endpoints)
            {
                if (endpoint.RegionIds.Contains(regionId))
                {
                    endpoint.ProductDomains.Add(productDomain);
                    return productDomain;
                }
            }

            ISet<string> regionIds = new HashSet<String>();
            regionIds.Add(regionId);
            List<ProductDomain> productDomains = new List<ProductDomain>();
            productDomains.Add(productDomain);

            endpoints.Add(new Endpoint(regionId, regionIds, productDomains));
            return productDomain;
        }
 private static ProductDomain GetProductDomainByLocation(String regionId,
         String product, IAcsClient acsClient)
 {
     DescribeEndpointRequest describeEndpointRequest = new DescribeEndpointRequest();
     describeEndpointRequest.RegionId = regionId;
     describeEndpointRequest.SetService(product.ToLower());
     //DescribeEndpointResponse describeEndpointResponse = acsClient.getAcsResponse(describeEndpointRequest);
     //ProductDomain productDomain = new ProductDomain(product, describeEndpointResponse.Endpoint);
     //return productDomain;
     return null;
 }