summaryrefslogtreecommitdiffstats
path: root/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.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/Google/GoogleClient.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/Google/GoogleClient.cs')
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs16
1 files changed, 8 insertions, 8 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs b/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs
index 1e1a486..679955a 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.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;
@@ -32,15 +35,12 @@ namespace DotNetOpenAuth.ApplicationBlock {
: base(GoogleDescription) {
}
- 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://www.googleapis.com/oauth2/v1/userinfo?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://www.googleapis.com/oauth2/v1/userinfo", cancellationToken)) {
+ response.EnsureSuccessStatusCode();
+ using (var responseStream = await response.Content.ReadAsStreamAsync()) {
return GoogleGraph.Deserialize(responseStream);
}
}