示例#1
0
        public async Task <ListResponse <Notebook> > GetFilesAsync(EntityHeader org, EntityHeader user)
        {
            var hub = await _hubManager.GetHubForOrgAsync(org, user);

            var uri       = $"{hub.Result.GetFullUri()}/user/{org.Id}/api/contents/nuviot?type=directory&_=1535292903800&token={hub.Result.AccessToken}";
            var userToken = "68d425712f6c4cb89d4ce3b2a4c269d5";
            var client    = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue($"token", userToken);
            var json = await client.GetStringAsync(uri);

            Console.WriteLine(json);
            var files = JsonConvert.DeserializeObject <List <Notebook> >(json);

            return(ListResponse <Notebook> .Create(files));
        }
示例#2
0
        public async Task <InvokeResult <TokenResponse> > GetOrgAccessToken(EntityHeader org, EntityHeader user)
        {
            var hub = await _hubManager.GetHubForOrgAsync(org, user);

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue($"token", hub.Result.AccessToken);
            var uri      = $"{hub.Result.GetFullUri()}/hub/api/users/{org.Id}/tokens";
            var response = await client.PostAsync(uri, new StringContent(String.Empty));

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var tokenResponse = JsonConvert.DeserializeObject <TokenResponse>(json);
                return(InvokeResult <TokenResponse> .Create(tokenResponse));
            }
            else
            {
                return(InvokeResult <TokenResponse> .FromError($"Non success code from server: {response.ReasonPhrase}"));
            }
        }