public async void Load() { AppAuthenticationDetails authDetails = new AppAuthenticationDetails() { AccessToken = "u:2eed4d61", MacAlgorithm = "hmac-sha-256", MacKey = "46832ba535c87f3ac4e2a5d8d7b98ae0", TokenType = "mac" }; client = await TentClient.Connect("tomasmcguinness.tent.is", authDetails); foreach (var follower in await client.GetFollowers()) { Followings.Add(follower); } foreach (var post in await client.GetPosts()) { StatusUpdates.Add(post); } }
/// <summary> /// Returns an instance of a TentClient connected and authorized to the target server. /// </summary> /// <param name="serverName"></param> /// <param name="authDetails"></param> /// <returns></returns> public async static Task<TentClient> Connect(string serverName, AppAuthenticationDetails authDetails) { string apiPath = await GetApiPath(serverName); return new TentClient(serverName, apiPath, authDetails); }
private TentClient(string serverName, string apiPath, AppAuthenticationDetails authDetails) { this.serverName = serverName; this.apiPath = apiPath; this.authenticationDetails = authDetails; }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task<String> Register(RegistrationRequest request) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.tent.v0+json")); HttpContent body = new ObjectContent(request.GetType(), request, new JsonMediaTypeFormatter(), "application/vnd.tent.v0+json"); HttpResponseMessage response = await client.PostAsync(ServerUri("apps"), body); response.EnsureSuccessStatusCode(); var registrationResult = await response.Content.ReadAsAsync<RegistrationResponse>(new List<MediaTypeFormatter>() { new TentJsonMediaTypeFormatter() }); authenticationDetails = new AppAuthenticationDetails() { ApplicationId = registrationResult.Id, MacKey = registrationResult.MacKey, MacAlgorithm = registrationResult.MacAlgorithm, MacKeyIdentifier = registrationResult.MacKeyIdentifier, TokenType = "mac" }; var oauthUrl = new StringBuilder(); oauthUrl.Append(ServerUri("/oauth/authorize")); oauthUrl.AppendFormat("?client_id={0}", registrationResult.Id); oauthUrl.AppendFormat("&redirect_uri={0}", request.RedirectUris[0]); oauthUrl.AppendFormat("&scope={0}", "write_posts,read_posts,read_followers"); //oauthUrl.AppendFormat("&state={0}", new Random().Next()); //oauthUrl.AppendFormat("&tent_profile_info_types={0}", "https://tent.io/types/info/music/v0.1.0"); //oauthUrl.AppendFormat("&tent_post_types={0}", "https://tent.io/types/posts/status/v0.1.0"); return oauthUrl.ToString(); }