summaryrefslogtreecommitdiffstats
path: root/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-07-31 22:01:16 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-07-31 22:01:16 -0700
commitc94c7f8197eda673947a9d1e0c0b3f3c4efca94f (patch)
tree0f978cfc2de70c54ac81e11d4339da04dff9f27f /samples/OAuthServiceProvider/Members/Authorize.aspx.cs
parent7d38eefb65928a1e80036ec006b0e129dc2cface (diff)
downloadDotNetOpenAuth-c94c7f8197eda673947a9d1e0c0b3f3c4efca94f.zip
DotNetOpenAuth-c94c7f8197eda673947a9d1e0c0b3f3c4efca94f.tar.gz
DotNetOpenAuth-c94c7f8197eda673947a9d1e0c0b3f3c4efca94f.tar.bz2
Split the OAuthServiceProvider sample into two samples: OAuthAuthorizationServer and OAuthResourceServer.
Renamed OAuthConsumer to OAuthClient.
Diffstat (limited to 'samples/OAuthServiceProvider/Members/Authorize.aspx.cs')
-rw-r--r--samples/OAuthServiceProvider/Members/Authorize.aspx.cs76
1 files changed, 0 insertions, 76 deletions
diff --git a/samples/OAuthServiceProvider/Members/Authorize.aspx.cs b/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
deleted file mode 100644
index 4cb266f..0000000
--- a/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-namespace OAuthServiceProvider.Members {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Security.Cryptography;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Code;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2;
- using DotNetOpenAuth.OAuth2.Messages;
-
- public partial class Authorize2 : System.Web.UI.Page {
- private static readonly RandomNumberGenerator CryptoRandomDataGenerator = new RNGCryptoServiceProvider();
-
- private EndUserAuthorizationRequest pendingRequest;
-
- private Client client;
-
- private string AuthorizationSecret {
- get { return Session["OAuthAuthorizationSecret"] as string; }
- set { Session["OAuthAuthorizationSecret"] = value; }
- }
-
- protected void Page_Load(object sender, EventArgs e) {
- var getRequest = new HttpRequestInfo("GET", this.Request.Url, this.Request.RawUrl, new WebHeaderCollection(), null);
- this.pendingRequest = Global.AuthorizationServer.ReadAuthorizationRequest(getRequest);
- if (this.pendingRequest == null) {
- throw new HttpException((int)HttpStatusCode.BadRequest, "Missing authorization request.");
- }
-
- this.client = Global.DataContext.Clients.First(c => c.ClientIdentifier == this.pendingRequest.ClientIdentifier);
-
- var authServer = new OAuth2AuthorizationServer();
- if (authServer.CanBeAutoApproved(this.pendingRequest)) {
- Global.AuthorizationServer.ApproveAuthorizationRequest(this.pendingRequest, User.Identity.Name);
- }
-
- if (!IsPostBack) {
- this.desiredAccessLabel.Text = OAuthUtilities.JoinScopes(this.pendingRequest.Scope);
- this.consumerLabel.Text = this.client.Name;
-
- // 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.
- var randomData = new byte[8];
- CryptoRandomDataGenerator.GetBytes(randomData);
- this.AuthorizationSecret = Convert.ToBase64String(randomData);
- this.OAuthAuthorizationSecToken.Value = this.AuthorizationSecret;
- }
- }
-
- protected void allowAccessButton_Click(object sender, EventArgs e) {
- if (this.AuthorizationSecret != this.OAuthAuthorizationSecToken.Value) {
- throw new ArgumentException(); // probably someone trying to hack in.
- }
- this.AuthorizationSecret = null; // clear one time use secret
- this.multiView.SetActiveView(this.AuthGranted);
-
- this.client.ClientAuthorizations.Add(
- new ClientAuthorization {
- Scope = OAuthUtilities.JoinScopes(this.pendingRequest.Scope),
- User = Global.LoggedInUser,
- CreatedOnUtc = DateTime.UtcNow,
- });
- Global.AuthorizationServer.ApproveAuthorizationRequest(this.pendingRequest, User.Identity.Name);
- }
-
- protected void denyAccessButton_Click(object sender, EventArgs e) {
- Global.AuthorizationServer.RejectAuthorizationRequest(this.pendingRequest);
- }
- }
-} \ No newline at end of file