summaryrefslogtreecommitdiffstats
path: root/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-05-27 09:46:47 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-05-27 09:46:47 -0700
commit7fda43b0eece0204231bfbda881ada7e8fbb035b (patch)
tree105a74788a5849b0fbf827df094aa2f9d876cd50 /samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs
parent5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba (diff)
downloadDotNetOpenAuth-7fda43b0eece0204231bfbda881ada7e8fbb035b.zip
DotNetOpenAuth-7fda43b0eece0204231bfbda881ada7e8fbb035b.tar.gz
DotNetOpenAuth-7fda43b0eece0204231bfbda881ada7e8fbb035b.tar.bz2
Made AppBlock GetGraph methods async
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs')
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs19
1 files changed, 10 insertions, 9 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs b/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs
index 7f7af18..749ab0d 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveClient.cs
@@ -10,7 +10,10 @@ namespace DotNetOpenAuth.ApplicationBlock {
using System.IO;
using System.Linq;
using System.Net;
+ using System.Net.Http;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
@@ -29,15 +32,12 @@ namespace DotNetOpenAuth.ApplicationBlock {
: base(WindowsLiveDescription) {
}
- public IOAuth2Graph GetGraph(IAuthorizationState authState, string[] fields = null) {
+ public async Task<IOAuth2Graph> GetGraphAsync(IAuthorizationState authState, string[] fields = null, CancellationToken cancellationToken = default(CancellationToken)) {
if ((authState != null) && (authState.AccessToken != null)) {
- WebRequest request = WebRequest.Create("https://apis.live.net/v5.0/me?access_token=" + Uri.EscapeDataString(authState.AccessToken));
- WebResponse response = request.GetResponse();
-
- if (response != null) {
- Stream responseStream = response.GetResponseStream();
-
- if (responseStream != null) {
+ var httpClient = new HttpClient(this.CreateAuthorizingHandler(authState));
+ using (var response = await httpClient.GetAsync("https://apis.live.net/v5.0/me", cancellationToken)) {
+ response.EnsureSuccessStatusCode();
+ using (var responseStream = await response.Content.ReadAsStreamAsync()) {
// string debugJsonStr = new StreamReader(responseStream).ReadToEnd();
WindowsLiveGraph windowsLiveGraph = WindowsLiveGraph.Deserialize(responseStream);
@@ -45,7 +45,8 @@ namespace DotNetOpenAuth.ApplicationBlock {
// &type=small 96x96
// &type=medium 96x96
// &type=large 448x448
- windowsLiveGraph.AvatarUrl = new Uri("https://apis.live.net/v5.0/me/picture?access_token=" + Uri.EscapeDataString(authState.AccessToken));
+ windowsLiveGraph.AvatarUrl =
+ new Uri("https://apis.live.net/v5.0/me/picture?access_token=" + Uri.EscapeDataString(authState.AccessToken));
return windowsLiveGraph;
}