diff options
Diffstat (limited to 'samples/OAuthClient/Facebook.aspx.cs')
-rw-r--r-- | samples/OAuthClient/Facebook.aspx.cs | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/samples/OAuthClient/Facebook.aspx.cs b/samples/OAuthClient/Facebook.aspx.cs index 3a9cf14..19211bc 100644 --- a/samples/OAuthClient/Facebook.aspx.cs +++ b/samples/OAuthClient/Facebook.aspx.cs @@ -3,6 +3,8 @@ using System.Configuration; using System.Net; using System.Web; + using System.Web.UI; + using DotNetOpenAuth.ApplicationBlock; using DotNetOpenAuth.ApplicationBlock.Facebook; using DotNetOpenAuth.Messaging; @@ -14,22 +16,30 @@ ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["facebookAppSecret"]), }; - protected async void Page_Load(object sender, EventArgs e) { - IAuthorizationState authorization = await client.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), Response.ClientDisconnectedToken); - if (authorization == null) { - // Kick off authorization request - var request = await client.PrepareRequestUserAuthorizationAsync(cancellationToken: Response.ClientDisconnectedToken); - await request.SendAsync(new HttpContextWrapper(Context), Response.ClientDisconnectedToken); - this.Context.Response.End(); - } else { - var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken)); - using (var response = request.GetResponse()) { - using (var responseStream = response.GetResponseStream()) { - var graph = FacebookGraph.Deserialize(responseStream); - this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name); - } - } - } + protected void Page_Load(object sender, EventArgs e) { + this.RegisterAsyncTask( + new PageAsyncTask( + async ct => { + IAuthorizationState authorization = + await client.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), ct); + if (authorization == null) { + // Kick off authorization request + var request = + await client.PrepareRequestUserAuthorizationAsync(cancellationToken: ct); + await request.SendAsync(new HttpContextWrapper(Context), ct); + this.Context.Response.End(); + } else { + var request = + WebRequest.Create( + "https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken)); + using (var response = request.GetResponse()) { + using (var responseStream = response.GetResponseStream()) { + var graph = FacebookGraph.Deserialize(responseStream); + this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name); + } + } + } + })); } } }
\ No newline at end of file |