Exemplo n.º 1
0
 public TestTask(String name, String messageType, String queueName, IAcsClient acsClient)
 {
     this.name        = name;
     this.messageType = messageType;
     this.queueName   = queueName;
     this.acsClient   = acsClient;
 }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 public MainTask(String name, String messageType, String queueName, IAcsClient acsClient)
 {
     this.Name        = name;
     this.MessageType = messageType;
     this.QueueName   = queueName;
     this.AcsClient   = acsClient;
 }
Exemplo n.º 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)));
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 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";
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 23
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 GetEndpointByLocation(regionId, product, endpoints, acsClient);
 }
Exemplo n.º 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);
 }
Exemplo n.º 25
0
 public STSAssumeRoleSessionCredentialsProvider WithSTSClient(IAcsClient client)
 {
     this.stsClient = client;
     return(this);
 }
Exemplo n.º 26
0
 public RsaKeyPairCredentialProvider WithSTSClient(IAcsClient client)
 {
     this.stsClient = client;
     return(this);
 }
Exemplo n.º 27
0
 public RsaKeyPairCredentialProvider(RsaKeyPairCredential rsaKeyPairCredential, IClientProfile profile)
 {
     this.rsaKeyPairCredential = rsaKeyPairCredential;
     this.stsClient            = new DefaultAcsClient(profile, rsaKeyPairCredential);
 }
Exemplo n.º 28
0
 public void WithSTSClient(IAcsClient client)
 {
     stsClient = client;
 }
Exemplo n.º 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);
        }
Exemplo n.º 31
0
 // 初始化环境
 private static void InitData()
 {
     acsClient = InitAcsClient(regionIdForPop, accessId, accessSecret, productName, domainForPop);
 }
Exemplo n.º 32
0
        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;
        }
Exemplo n.º 33
0
 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;
 }