public async Task <AiurProtocol> CreateNewRecordAsync(
            string accessToken,
            string newRecordName,
            string targetUrl,
            string[] tags,
            RecordType type,
            bool enabled)
        {
            var url  = new AiurUrl(_serviceLocation.Endpoint, "Records", "CreateNewRecord", new { });
            var form = new AiurUrl(string.Empty, new CreateNewRecordAddressModel
            {
                AccessToken   = accessToken,
                NewRecordName = newRecordName,
                TargetUrl     = targetUrl,
                Type          = type,
                Enabled       = enabled,
                Tags          = string.Join(',', tags.Select(t => t.Trim()))
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="siteName"></param>
        /// <param name="permissions">Upload, Download</param>
        /// <param name="underPath"></param>
        /// <param name="lifespan"></param>
        /// <returns></returns>
        public async Task <string> GetTokenAsync(
            string accessToken,
            string siteName,
            string[] permissions,
            string underPath,
            TimeSpan lifespan)
        {
            var url  = new AiurUrl(_serviceLocation.Endpoint, "Token", "GetToken", new { });
            var form = new AiurUrl(string.Empty, new GetTokenAddressModel
            {
                AccessToken     = accessToken,
                SiteName        = siteName,
                Permissions     = string.Join(",", permissions),
                UnderPath       = underPath,
                LifespanSeconds = (long)lifespan.TotalSeconds
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurValue <string> >(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult.Value);
        }
Beispiel #3
0
        private async Task <string> GetAccessToken(string clientId, string clientSecret, string code, bool isBinding)
        {
            var apiAddress = "https://graph.facebook.com/v5.0/oauth/access_token?";
            var url        = new AiurUrl(apiAddress, new { });
            var action     = isBinding ? "bind-account" : "sign-in";
            var form       = new AiurUrl(string.Empty, new FaceBookAccessTokenAddressModel
            {
                ClientId     = clientId,
                ClientSecret = clientSecret,
                Code         = code,
                RedirectUri  = new AiurUrl(_serviceLocation.Endpoint, $"/third-party/{action}/{GetName()}", new { }).ToString()
            });

            try
            {
                var json = await _http.Post(url, form);

                var response = JsonConvert.DeserializeObject <AccessTokenResponse>(json);
                if (string.IsNullOrWhiteSpace(response.AccessToken))
                {
                    throw new AiurAPIModelException(ErrorType.Unauthorized, "Invalid facebook credential");
                }
                return(response.AccessToken);
            }
            catch (WebException)
            {
                throw new AiurAPIModelException(ErrorType.Unauthorized, "Invalid facebook credential");
            }
        }
Beispiel #4
0
        private async Task <string> GetAccessToken(string clientId, string clientSecret, string code, bool isBinding)
        {
            var apiAddress = "https://login.microsoftonline.com" + $"/{_tenant}/oauth2/v2.0/token";
            var url        = new AiurUrl(apiAddress, new { });
            var action     = isBinding ? "bind-account" : "sign-in";
            var form       = new AiurUrl(string.Empty, new MicrosoftAccessTokenAddressModel
            {
                ClientId     = clientId,
                ClientSecret = clientSecret,
                Code         = code,
                Scope        = "user.read",
                RedirectUri  = new AiurUrl(_serviceLocation.Endpoint, $"/third-party/{action}/{GetName()}", new { }).ToString(),
                GrantType    = "authorization_code"
            });

            try
            {
                var json = await _http.Post(url, form);

                var response = JsonConvert.DeserializeObject <AccessTokenResponse>(json);
                if (string.IsNullOrWhiteSpace(response.AccessToken))
                {
                    throw new AiurAPIModelException(ErrorType.Unauthorized, "Invalid Microsoft crenditial");
                }
                return(response.AccessToken);
            }
            catch (WebException)
            {
                throw new AiurAPIModelException(ErrorType.Unauthorized, "Invalid Microsoft crenditial");
            }
        }
Beispiel #5
0
        public async Task <AiurProtocol> DeleteFileAsync(string accessToken, string siteName, string folderNames)
        {
            var url  = new AiurUrl(_serviceLocation.Endpoint, $"/Files/DeleteFile/{siteName.ToUrlEncoded()}/{folderNames.EncodePath()}", new { });
            var form = new AiurUrl(string.Empty, new DeleteFileAddressModel
            {
                AccessToken = accessToken
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
        public async Task <AiurProtocol> CreateNewFolderAsync(string accessToken, string siteName, string folderNames, string newFolderName, bool recursiveCreate)
        {
            var url  = new AiurUrl(_serviceLocation.Endpoint, $"/Folders/CreateNewFolder/{siteName.ToUrlEncoded()}/{folderNames.EncodePath()}", new { });
            var form = new AiurUrl(string.Empty, new CreateNewFolderAddressModel
            {
                AccessToken     = accessToken,
                NewFolderName   = newFolderName,
                RecursiveCreate = recursiveCreate
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
Beispiel #7
0
        public async Task <AiurProtocol> CreateNewSiteAsync(string accessToken, string newSiteName, bool openToUpload, bool openToDownload)
        {
            var url  = new AiurUrl(_probeLocator.Endpoint, "Sites", "CreateNewSite", new { });
            var form = new AiurUrl(string.Empty, new CreateNewSiteAddressModel
            {
                AccessToken    = accessToken,
                NewSiteName    = newSiteName,
                OpenToUpload   = openToUpload,
                OpenToDownload = openToDownload
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
Beispiel #8
0
        public async Task <AiurProtocol> LogAsync(string accessToken, string message, string stackTrace, EventLevel eventLevel, string path)
        {
            var url  = new AiurUrl(_observerLocator.Endpoint, "Event", "Log", new { });
            var form = new AiurUrl(string.Empty, new LogAddressModel
            {
                AccessToken = accessToken,
                Message     = message,
                StackTrace  = stackTrace,
                EventLevel  = eventLevel,
                Path        = path
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
        public async Task <AiurProtocol> DropGrantsAsync(string accessToken)
        {
            var url  = new AiurUrl(_serviceLocation.Endpoint, "API", "DropGrants", new { });
            var form = new AiurUrl(string.Empty, new
            {
                AccessToken = accessToken
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
Beispiel #10
0
        public async Task <CreateChannelViewModel> CreateChannelAsync(string accessToken, string description)
        {
            var url  = new AiurUrl(_stargateLocator.Endpoint, "Channel", "CreateChannel", new { });
            var form = new AiurUrl(string.Empty, new CreateChannelAddressModel
            {
                AccessToken = accessToken,
                Description = description
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <CreateChannelViewModel>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
        public async Task <AiurProtocol> PushMessageAsync(string accessToken, int channelId, object eventObject)
        {
            var url          = new AiurUrl(_stargateLocator.Endpoint, "Message", "PushMessage", new { });
            var payloadToken = JsonConvert.SerializeObject(eventObject, new JsonSerializerSettings()
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                ContractResolver     = new CamelCasePropertyNamesContractResolver(),
            });
            var form = new AiurUrl(string.Empty, new PushMessageAddressModel
            {
                AccessToken    = accessToken,
                ChannelId      = channelId,
                MessageContent = payloadToken
            });
            var result = await _httpService.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }
Beispiel #12
0
        public async Task <AiurProtocol> ChangeProfileAsync(string openId, string accessToken, string newNickName, string newIconFilePathName, string newBio)
        {
            var url  = new AiurUrl(_serviceLocation.Endpoint, "User", "ChangeProfile", new { });
            var form = new AiurUrl(string.Empty, new ChangeProfileAddressModel
            {
                AccessToken         = accessToken,
                OpenId              = openId,
                NewNickName         = newNickName,
                NewIconFilePathName = newIconFilePathName,
                NewBio              = newBio
            });
            var result = await _http.Post(url, form, true);

            var jResult = JsonConvert.DeserializeObject <AiurProtocol>(result);

            if (jResult.Code != ErrorType.Success)
            {
                throw new AiurUnexpectedResponse(jResult);
            }
            return(jResult);
        }