summaryrefslogtreecommitdiffstats
path: root/samples/OAuthClient/Google.aspx.cs
diff options
context:
space:
mode:
Diffstat (limited to 'samples/OAuthClient/Google.aspx.cs')
-rw-r--r--samples/OAuthClient/Google.aspx.cs34
1 files changed, 19 insertions, 15 deletions
diff --git a/samples/OAuthClient/Google.aspx.cs b/samples/OAuthClient/Google.aspx.cs
index fda643e..e0c4941 100644
--- a/samples/OAuthClient/Google.aspx.cs
+++ b/samples/OAuthClient/Google.aspx.cs
@@ -4,7 +4,9 @@
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 Google : System.Web.UI.Page
@@ -15,23 +17,25 @@
ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["googleClientSecret"]),
};
- protected void Page_Load(object sender, EventArgs e)
- {
- IAuthorizationState authorization = googleClient.ProcessUserAuthorization();
- if (authorization == null)
- {
- // Kick off authorization request
- googleClient.RequestUserAuthorization();
+ protected void Page_Load(object sender, EventArgs e) {
+ this.RegisterAsyncTask(
+ new PageAsyncTask(
+ async ct => {
+ IAuthorizationState authorization = await googleClient.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), ct);
+ if (authorization == null) {
+ // Kick off authorization request
+ var request = await googleClient.PrepareRequestUserAuthorizationAsync(cancellationToken: ct);
+ await request.SendAsync(new HttpContextWrapper(Context), ct);
+ this.Context.Response.End();
- // alternatively you can ask for more information
- // googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.UserInfo.Profile, GoogleClient.Scopes.UserInfo.Email });
- }
- else
- {
- IOAuth2Graph oauth2Graph = googleClient.GetGraph(authorization);
+ // alternatively you can ask for more information
+ // googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.UserInfo.Profile, GoogleClient.Scopes.UserInfo.Email });
+ } else {
+ IOAuth2Graph oauth2Graph = await googleClient.GetGraphAsync(authorization, cancellationToken: ct);
- this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
- }
+ this.nameLabel.Text = HttpUtility.HtmlEncode(oauth2Graph.Name);
+ }
+ }));
}
}
} \ No newline at end of file