blob: d139e4f8448ad95ab2f33762d26ccc859628980d (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
namespace OAuthConsumer {
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.ApplicationBlock;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth;
public partial class Yammer : System.Web.UI.Page {
private AccessToken AccessToken {
get { return (AccessToken)Session["YammerAccessToken"]; }
set { Session["YammerAccessToken"] = value; }
}
protected void Page_Load(object sender, EventArgs e) {
var yammer = new YammerConsumer();
if (yammer.ConsumerKey != null) {
this.MultiView1.SetActiveView(this.BeginAuthorizationView);
}
}
protected void getYammerMessages_Click(object sender, EventArgs e) {
var yammer = new YammerConsumer();
// TODO: code here
}
protected void obtainAuthorizationButton_Click(object sender, EventArgs e) {
this.RegisterAsyncTask(
new PageAsyncTask(
async ct => {
var yammer = new YammerConsumer();
Uri popupWindowLocation = await yammer.RequestUserAuthorizationAsync(MessagingUtilities.GetPublicFacingUrl());
string javascript = "window.open('" + popupWindowLocation.AbsoluteUri + "');";
this.Page.ClientScript.RegisterStartupScript(GetType(), "YammerPopup", javascript, true);
this.MultiView1.SetActiveView(this.CompleteAuthorizationView);
}));
}
protected void finishAuthorizationButton_Click(object sender, EventArgs e) {
this.RegisterAsyncTask(
new PageAsyncTask(
async ct => {
if (!Page.IsValid) {
return;
}
var yammer = new YammerConsumer();
var authorizationResponse = await yammer.ProcessUserAuthorizationAsync(this.yammerUserCode.Text);
if (authorizationResponse != null) {
this.accessTokenLabel.Text = HttpUtility.HtmlEncode(authorizationResponse.AccessToken);
this.MultiView1.SetActiveView(this.AuthorizationCompleteView);
} else {
this.MultiView1.SetActiveView(this.BeginAuthorizationView);
this.authorizationErrorLabel.Visible = true;
}
}));
}
}
}
|