diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-08-01 07:37:21 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-08-01 08:58:43 -0700 |
commit | 222762e7b5d664f3e86683a55be6ea84710efc69 (patch) | |
tree | a37153096500bb86d4f8fbea4045f3cce93dfbc7 /samples/OAuthClient/SampleWcf2.aspx.cs | |
parent | e7743dd039bab3788e682833368ca5a376b22354 (diff) | |
download | DotNetOpenAuth-222762e7b5d664f3e86683a55be6ea84710efc69.zip DotNetOpenAuth-222762e7b5d664f3e86683a55be6ea84710efc69.tar.gz DotNetOpenAuth-222762e7b5d664f3e86683a55be6ea84710efc69.tar.bz2 |
Some user-notification enhancements to the OAuth 2 samples.
Diffstat (limited to 'samples/OAuthClient/SampleWcf2.aspx.cs')
-rw-r--r-- | samples/OAuthClient/SampleWcf2.aspx.cs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/samples/OAuthClient/SampleWcf2.aspx.cs b/samples/OAuthClient/SampleWcf2.aspx.cs index 41f2896..7e0ea10 100644 --- a/samples/OAuthClient/SampleWcf2.aspx.cs +++ b/samples/OAuthClient/SampleWcf2.aspx.cs @@ -56,16 +56,22 @@ // We are receiving an authorization response. Store it and associate it with this user. Authorization = authorization; Response.Redirect(Request.Path); // get rid of the /?code= parameter - } else { - if (Authorization != null) { - // Indicate to the user that we have already obtained authorization on some of these. - foreach (var li in this.scopeList.Items.OfType<ListItem>().Where(li => Authorization.Scope.Contains(li.Value))) { - li.Selected = true; - } - authorizationLabel.Text = "Authorization received!"; - } } } + + if (Authorization != null) { + // Indicate to the user that we have already obtained authorization on some of these. + foreach (var li in this.scopeList.Items.OfType<ListItem>().Where(li => Authorization.Scope.Contains(li.Value))) { + li.Selected = true; + } + authorizationLabel.Text = "Authorization received!"; + if (Authorization.AccessTokenExpirationUtc.HasValue) { + TimeSpan timeLeft = Authorization.AccessTokenExpirationUtc.Value - DateTime.UtcNow; + authorizationLabel.Text += string.Format(CultureInfo.CurrentCulture, " (access token expires in {0} minutes)", Math.Round(timeLeft.TotalMinutes, 1)); + } + } + + this.getNameButton.Enabled = this.getAgeButton.Enabled = this.getFavoriteSites.Enabled = Authorization != null; } protected void getAuthorizationButton_Click(object sender, EventArgs e) { @@ -111,7 +117,10 @@ // Refresh the access token if it expires and if its lifetime is too short to be of use. if (Authorization.AccessTokenExpirationUtc.HasValue) { - Client.RefreshToken(Authorization, TimeSpan.FromMinutes(1)); + if (Client.RefreshToken(Authorization, TimeSpan.FromSeconds(30))) { + TimeSpan timeLeft = Authorization.AccessTokenExpirationUtc.Value - DateTime.UtcNow; + authorizationLabel.Text += string.Format(CultureInfo.CurrentCulture, " - just renewed for {0} more minutes)", Math.Round(timeLeft.TotalMinutes, 1)); + } } var httpRequest = (HttpWebRequest)WebRequest.Create(wcfClient.Endpoint.Address.Uri); |