blob: 9470ef088e9c53cee3ca7847842e45e1b844f91c (
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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
//-----------------------------------------------------------------------
// <copyright file="OpenIdInfoCardSelector.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.RelyingParty {
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IdentityModel.Claims;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using DotNetOpenAuth.ComponentModel;
using DotNetOpenAuth.InfoCard;
////using DotNetOpenAuth.InfoCard;
using DotNetOpenAuth.Messaging;
using Validation;
/// <summary>
/// An ASP.NET control that provides a user-friendly way of logging into a web site using OpenID.
/// </summary>
[ToolboxData("<{0}:OpenIdInfoCardSelector runat=\"server\"></{0}:OpenIdInfoCardSelector>")]
public class OpenIdInfoCardSelector : OpenIdSelector {
/// <summary>
/// The InfoCard selector button.
/// </summary>
private SelectorInfoCardButton selectorButton;
/// <summary>
/// Occurs when an InfoCard has been submitted and decoded.
/// </summary>
public event EventHandler<ReceivedTokenEventArgs> ReceivedToken;
/// <summary>
/// Occurs when [token processing error].
/// </summary>
public event EventHandler<TokenProcessingErrorEventArgs> TokenProcessingError;
/// <summary>
/// Ensures that the child controls have been built, but doesn't set control
/// properties that require executing <see cref="Control.EnsureID"/> in order to avoid
/// certain initialization order problems.
/// </summary>
/// <remarks>
/// We don't just call EnsureChildControls() and then set the property on
/// this.textBox itself because (apparently) setting this property in the ASPX
/// page and thus calling this EnsureID() via EnsureChildControls() this early
/// results in no ID.
/// </remarks>
protected override void EnsureChildControlsAreCreatedSafe() {
if (this.selectorButton == null) {
this.selectorButton = this.Buttons.OfType<SelectorInfoCardButton>().FirstOrDefault();
if (this.selectorButton != null) {
var selector = this.selectorButton.InfoCardSelector;
selector.ClaimsRequested.Add(new ClaimType { Name = ClaimTypes.PPID });
selector.ImageSize = InfoCardImageSize.Size60x42;
selector.ReceivedToken += this.InfoCardSelector_ReceivedToken;
selector.TokenProcessingError += this.InfoCardSelector_TokenProcessingError;
this.Controls.Add(selector);
}
}
base.EnsureChildControlsAreCreatedSafe();
}
/// <summary>
/// Fires the <see cref="ReceivedToken"/> event.
/// </summary>
/// <param name="e">The token, if it was decrypted.</param>
protected virtual void OnReceivedToken(ReceivedTokenEventArgs e) {
Requires.NotNull(e, "paramName");
var receivedInfoCard = this.ReceivedToken;
if (receivedInfoCard != null) {
receivedInfoCard(this, e);
}
}
/// <summary>
/// Raises the <see cref="E:TokenProcessingError"/> event.
/// </summary>
/// <param name="e">The <see cref="DotNetOpenAuth.InfoCard.TokenProcessingErrorEventArgs"/> instance containing the event data.</param>
protected virtual void OnTokenProcessingError(TokenProcessingErrorEventArgs e) {
Requires.NotNull(e, "paramName");
var tokenProcessingError = this.TokenProcessingError;
if (tokenProcessingError != null) {
tokenProcessingError(this, e);
}
}
/// <summary>
/// Handles the ReceivedToken event of the infoCardSelector control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="DotNetOpenAuth.InfoCard.ReceivedTokenEventArgs"/> instance containing the event data.</param>
private void InfoCardSelector_ReceivedToken(object sender, ReceivedTokenEventArgs e) {
this.Page.Response.SetCookie(new HttpCookie("openid_identifier", "infocard") {
Path = this.Page.Request.ApplicationPath,
});
this.OnReceivedToken(e);
}
/// <summary>
/// Handles the TokenProcessingError event of the infoCardSelector control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="DotNetOpenAuth.InfoCard.TokenProcessingErrorEventArgs"/> instance containing the event data.</param>
private void InfoCardSelector_TokenProcessingError(object sender, TokenProcessingErrorEventArgs e) {
this.OnTokenProcessingError(e);
}
}
}
|