summaryrefslogtreecommitdiffstats
path: root/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-04-19 07:09:32 -0400
committerAndrew Arnott <andrewarnott@gmail.com>2010-04-19 07:09:32 -0400
commit668c50fd19dc633bd367ac8ace37df8b5f9a5881 (patch)
tree8ab71b553fa22e12aae6817b3c6fab93acdd31df /samples/OAuthServiceProvider/Members/Authorize.aspx.cs
parentfef932af78eac2b775452c4a851e84a813027548 (diff)
downloadDotNetOpenAuth-668c50fd19dc633bd367ac8ace37df8b5f9a5881.zip
DotNetOpenAuth-668c50fd19dc633bd367ac8ace37df8b5f9a5881.tar.gz
DotNetOpenAuth-668c50fd19dc633bd367ac8ace37df8b5f9a5881.tar.bz2
Updated OAuth C and SP samples to use standard WAP namespaces.
Diffstat (limited to 'samples/OAuthServiceProvider/Members/Authorize.aspx.cs')
-rw-r--r--samples/OAuthServiceProvider/Members/Authorize.aspx.cs129
1 files changed, 66 insertions, 63 deletions
diff --git a/samples/OAuthServiceProvider/Members/Authorize.aspx.cs b/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
index 1e981a3..ec98ddf 100644
--- a/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
+++ b/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
@@ -1,77 +1,80 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Web;
-using System.Web.UI;
-using System.Web.UI.WebControls;
-using DotNetOpenAuth;
-using DotNetOpenAuth.OAuth;
-using DotNetOpenAuth.OAuth.Messages;
+namespace OAuthServiceProvider {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Security.Cryptography;
+ using System.Web;
+ using System.Web.UI;
+ using System.Web.UI.WebControls;
+ using DotNetOpenAuth;
+ using DotNetOpenAuth.OAuth;
+ using DotNetOpenAuth.OAuth.Messages;
+ using OAuthServiceProvider.Code;
-/// <summary>
-/// Conducts the user through a Consumer authorization process.
-/// </summary>
-public partial class Authorize : System.Web.UI.Page {
- private static readonly RandomNumberGenerator CryptoRandomDataGenerator = new RNGCryptoServiceProvider();
+ /// <summary>
+ /// Conducts the user through a Consumer authorization process.
+ /// </summary>
+ public partial class Authorize : System.Web.UI.Page {
+ private static readonly RandomNumberGenerator CryptoRandomDataGenerator = new RNGCryptoServiceProvider();
- private string AuthorizationSecret {
- get { return Session["OAuthAuthorizationSecret"] as string; }
- set { Session["OAuthAuthorizationSecret"] = value; }
- }
+ private string AuthorizationSecret {
+ get { return Session["OAuthAuthorizationSecret"] as string; }
+ set { Session["OAuthAuthorizationSecret"] = value; }
+ }
- protected void Page_Load(object sender, EventArgs e) {
- if (!IsPostBack) {
- if (Global.PendingOAuthAuthorization == null) {
- Response.Redirect("~/Members/AuthorizedConsumers.aspx");
- } else {
- ITokenContainingMessage pendingToken = Global.PendingOAuthAuthorization;
- var token = Global.DataContext.OAuthTokens.Single(t => t.Token == pendingToken.Token);
- desiredAccessLabel.Text = token.Scope;
- consumerLabel.Text = Global.TokenManager.GetConsumerForToken(token.Token).ConsumerKey;
+ protected void Page_Load(object sender, EventArgs e) {
+ if (!IsPostBack) {
+ if (Global.PendingOAuthAuthorization == null) {
+ Response.Redirect("~/Members/AuthorizedConsumers.aspx");
+ } else {
+ ITokenContainingMessage pendingToken = Global.PendingOAuthAuthorization;
+ var token = Global.DataContext.OAuthTokens.Single(t => t.Token == pendingToken.Token);
+ desiredAccessLabel.Text = token.Scope;
+ consumerLabel.Text = Global.TokenManager.GetConsumerForToken(token.Token).ConsumerKey;
- // Generate an unpredictable secret that goes to the user agent and must come back
- // with authorization to guarantee the user interacted with this page rather than
- // being scripted by an evil Consumer.
- byte[] randomData = new byte[8];
- CryptoRandomDataGenerator.GetBytes(randomData);
- this.AuthorizationSecret = Convert.ToBase64String(randomData);
- OAuthAuthorizationSecToken.Value = this.AuthorizationSecret;
+ // Generate an unpredictable secret that goes to the user agent and must come back
+ // with authorization to guarantee the user interacted with this page rather than
+ // being scripted by an evil Consumer.
+ byte[] randomData = new byte[8];
+ CryptoRandomDataGenerator.GetBytes(randomData);
+ this.AuthorizationSecret = Convert.ToBase64String(randomData);
+ OAuthAuthorizationSecToken.Value = this.AuthorizationSecret;
- OAuth10ConsumerWarning.Visible = Global.PendingOAuthAuthorization.IsUnsafeRequest;
+ OAuth10ConsumerWarning.Visible = Global.PendingOAuthAuthorization.IsUnsafeRequest;
+ }
}
}
- }
- protected void allowAccessButton_Click(object sender, EventArgs e) {
- if (this.AuthorizationSecret != OAuthAuthorizationSecToken.Value) {
- throw new ArgumentException(); // probably someone trying to hack in.
- }
- this.AuthorizationSecret = null; // clear one time use secret
- var pending = Global.PendingOAuthAuthorization;
- Global.AuthorizePendingRequestToken();
- multiView.ActiveViewIndex = 1;
+ protected void allowAccessButton_Click(object sender, EventArgs e) {
+ if (this.AuthorizationSecret != OAuthAuthorizationSecToken.Value) {
+ throw new ArgumentException(); // probably someone trying to hack in.
+ }
+ this.AuthorizationSecret = null; // clear one time use secret
+ var pending = Global.PendingOAuthAuthorization;
+ Global.AuthorizePendingRequestToken();
+ multiView.ActiveViewIndex = 1;
- ServiceProvider sp = new ServiceProvider(Constants.SelfDescription, Global.TokenManager);
- var response = sp.PrepareAuthorizationResponse(pending);
- if (response != null) {
- sp.Channel.Send(response);
- } else {
- if (pending.IsUnsafeRequest) {
- verifierMultiView.ActiveViewIndex = 1;
+ ServiceProvider sp = new ServiceProvider(Constants.SelfDescription, Global.TokenManager);
+ var response = sp.PrepareAuthorizationResponse(pending);
+ if (response != null) {
+ sp.Channel.Send(response);
} else {
- string verifier = ServiceProvider.CreateVerificationCode(VerificationCodeFormat.AlphaNumericNoLookAlikes, 10);
- verificationCodeLabel.Text = verifier;
- ITokenContainingMessage requestTokenMessage = pending;
- var requestToken = Global.TokenManager.GetRequestToken(requestTokenMessage.Token);
- requestToken.VerificationCode = verifier;
- Global.TokenManager.UpdateToken(requestToken);
+ if (pending.IsUnsafeRequest) {
+ verifierMultiView.ActiveViewIndex = 1;
+ } else {
+ string verifier = ServiceProvider.CreateVerificationCode(VerificationCodeFormat.AlphaNumericNoLookAlikes, 10);
+ verificationCodeLabel.Text = verifier;
+ ITokenContainingMessage requestTokenMessage = pending;
+ var requestToken = Global.TokenManager.GetRequestToken(requestTokenMessage.Token);
+ requestToken.VerificationCode = verifier;
+ Global.TokenManager.UpdateToken(requestToken);
+ }
}
}
- }
- protected void denyAccessButton_Click(object sender, EventArgs e) {
- // erase the request token.
- multiView.ActiveViewIndex = 2;
+ protected void denyAccessButton_Click(object sender, EventArgs e) {
+ // erase the request token.
+ multiView.ActiveViewIndex = 2;
+ }
}
-}
+} \ No newline at end of file