-
Notifications
You must be signed in to change notification settings - Fork 0
/
openid.aspx.cs
95 lines (80 loc) · 2.66 KB
/
openid.aspx.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Specialized;
using ExtremeSwank.Authentication.OpenID;
using ExtremeSwank.Authentication.OpenID.Plugins.Extensions;
using WebComponents;
namespace Avalon.Web {
public partial class _openid : System.Web.UI.Page¡¡
{
protected void Page_Load(object sender, EventArgs e) {
NameValueCollection form;
form=Request.Form;
string method = HttpContext.Current.Request["m"];
switch (method)
{
case "login":
Login(form);
break;
case "logout":
Logout();
break;
case "check":
Check();
break;
}
if (!IsPostBack)
{
OpenIDConsumer openid = new OpenIDConsumer();
switch (openid.RequestedMode)
{
case RequestedMode.IdResolution:
openid.Identity = (string)Session["OpenID_Login"];
if (openid.Validate())
{
Session["OpenID_UserObject"] = openid.RetrieveUser();
// Authentication successful - Perform login here
Response.Redirect("/");
}
else
{
// Authentication failure handled here
System.Web.HttpContext.Current.Trace.Write("LoginFailure", openid.GetError());
Response.Redirect("/login?failure=" + openid.GetError());
}
break;
case RequestedMode.CancelledByUser:
// User has cancelled authentication - handle here
Response.Redirect("/error");
break;
}
}
}
protected void Check() {
if (Session["OpenID_UserObject"] != null)
{
status.Text="1";
}else{
status.Text="0";
}
}
protected void Login(NameValueCollection form) {
OpenIDConsumer openid = new OpenIDConsumer();
openid.Identity = HttpContext.Current.Request["opid"];
SimpleRegistration sr = new SimpleRegistration(openid);
sr.RequiredFields = "nickname,email";
sr.OptionalFields = "gender";
Session["OpenID_Identity"] = openid.Identity;
openid.BeginAuth();
}
protected void Logout() {
// Handle user logout here
// Session
Session["OpenID_UserObject"] = null;
// Return
Response.Redirect("/");
}
}
}