summaryrefslogtreecommitdiffstats
path: root/samples/OAuthClient/Facebook.aspx.cs
diff options
context:
space:
mode:
Diffstat (limited to 'samples/OAuthClient/Facebook.aspx.cs')
-rw-r--r--samples/OAuthClient/Facebook.aspx.cs37
1 files changed, 21 insertions, 16 deletions
diff --git a/samples/OAuthClient/Facebook.aspx.cs b/samples/OAuthClient/Facebook.aspx.cs
index 008baa8..101b7f6 100644
--- a/samples/OAuthClient/Facebook.aspx.cs
+++ b/samples/OAuthClient/Facebook.aspx.cs
@@ -4,7 +4,10 @@
using System.Configuration;
using System.Net;
using System.Web;
+ using System.Web.UI;
+
using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
public partial class Facebook : System.Web.UI.Page
@@ -15,24 +18,26 @@
ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["facebookAppSecret"]),
};
- protected void Page_Load(object sender, EventArgs e)
- {
- IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();
- if (authorization == null)
- {
- // Kick off authorization request
- facebookClient.RequestUserAuthorization();
+ protected void Page_Load(object sender, EventArgs e) {
+ this.RegisterAsyncTask(
+ new PageAsyncTask(
+ async ct => {
+ IAuthorizationState authorization = await facebookClient.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), ct);
+ if (authorization == null) {
+ // Kick off authorization request
+ var request = await facebookClient.PrepareRequestUserAuthorizationAsync(cancellationToken: ct);
+ await request.SendAsync(new HttpContextWrapper(Context), ct);
+ this.Context.Response.End();
- // alternatively you can ask for more information
- // facebookClient.RequestUserAuthorization(scope: new[] { FacebookClient.Scopes.Email, FacebookClient.Scopes.UserBirthday });
- }
- else
- {
- IOAuth2Graph oauth2Graph = facebookClient.GetGraph(authorization);
- //// IOAuth2Graph oauth2Graph = facebookClient.GetGraph(authorization, new[] { FacebookGraph.Fields.Defaults, FacebookGraph.Fields.Email, FacebookGraph.Fields.Picture, FacebookGraph.Fields.Birthday });
+ // alternatively you can ask for more information
+ // facebookClient.RequestUserAuthorization(scope: new[] { FacebookClient.Scopes.Email, FacebookClient.Scopes.UserBirthday });
+ } else {
+ IOAuth2Graph oauth2Graph = await facebookClient.GetGraphAsync(authorization, cancellationToken: ct);
+ //// IOAuth2Graph oauth2Graph = facebookClient.GetGraph(authorization, new[] { FacebookGraph.Fields.Defaults, FacebookGraph.Fields.Email, FacebookGraph.Fields.Picture, FacebookGraph.Fields.Birthday });
- this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
- }
+ this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
+ }
+ }));
}
}
} \ No newline at end of file