summaryrefslogtreecommitdiffstats
path: root/samples/OAuthServiceProvider/Members/Authorize.aspx.cs
blob: 76eec26eed26d18e3774b939b61af18f5040a418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.Messages;

/// <summary>
/// Conducts the user through a Consumer authorization process.
/// </summary>
public partial class Authorize : System.Web.UI.Page {
	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;
			}
		}
	}

	protected void allowAccessButton_Click(object sender, EventArgs e) {
		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);
		}
	}

	protected void denyAccessButton_Click(object sender, EventArgs e) {
		// erase the request token.
		multiView.ActiveViewIndex = 2;
	}
}