diff options
Diffstat (limited to 'samples/ProviderPortal/decide.aspx.cs')
-rw-r--r-- | samples/ProviderPortal/decide.aspx.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/samples/ProviderPortal/decide.aspx.cs b/samples/ProviderPortal/decide.aspx.cs new file mode 100644 index 0000000..1ca0138 --- /dev/null +++ b/samples/ProviderPortal/decide.aspx.cs @@ -0,0 +1,75 @@ +namespace OpenIdProviderWebForms { + using System; + using System.Diagnostics; + using System.Web.Security; + using System.Web.UI; + using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy; + using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; + using DotNetOpenAuth.OpenId.Provider; + + /// <summary> + /// Page for giving the user the option to continue or cancel out of authentication with a consumer. + /// </summary> + public partial class decide : Page { + protected void Page_Load(object src, EventArgs e) { + if (ProviderEndpoint.PendingAuthenticationRequest == null) { + Response.Redirect("~/"); + } + + if (ProviderEndpoint.PendingAuthenticationRequest.IsDirectedIdentity) { + ProviderEndpoint.PendingAuthenticationRequest.LocalIdentifier = Code.Util.BuildIdentityUrl(); + } + this.relyingPartyVerificationResultLabel.Text = + ProviderEndpoint.PendingAuthenticationRequest.IsReturnUrlDiscoverable ? "passed" : "failed"; + + this.identityUrlLabel.Text = ProviderEndpoint.PendingAuthenticationRequest.LocalIdentifier.ToString(); + this.realmLabel.Text = ProviderEndpoint.PendingAuthenticationRequest.Realm.ToString(); + + // check that the logged in user is the same as the user requesting authentication to the consumer. If not, then log them out. + if (string.Equals(User.Identity.Name, Code.Util.ExtractUserName(ProviderEndpoint.PendingAuthenticationRequest.LocalIdentifier), StringComparison.OrdinalIgnoreCase)) { + // if simple registration fields were used, then prompt the user for them + var requestedFields = ProviderEndpoint.PendingAuthenticationRequest.GetExtension<ClaimsRequest>(); + if (requestedFields != null) { + this.profileFields.Visible = true; + this.profileFields.SetRequiredFieldsFromRequest(requestedFields); + if (!IsPostBack) { + var sregResponse = requestedFields.CreateResponse(); + sregResponse.Email = Membership.GetUser().Email; + this.profileFields.SetOpenIdProfileFields(sregResponse); + } + } + } else { + FormsAuthentication.SignOut(); + Response.Redirect(Request.Url.AbsoluteUri); + } + } + + protected void Yes_Click(object sender, EventArgs e) { + var sregRequest = ProviderEndpoint.PendingAuthenticationRequest.GetExtension<ClaimsRequest>(); + ClaimsResponse sregResponse = null; + if (sregRequest != null) { + sregResponse = this.profileFields.GetOpenIdProfileFields(sregRequest); + ProviderEndpoint.PendingAuthenticationRequest.AddResponseExtension(sregResponse); + } + var papeRequest = ProviderEndpoint.PendingAuthenticationRequest.GetExtension<PolicyRequest>(); + PolicyResponse papeResponse = null; + if (papeRequest != null) { + papeResponse = new PolicyResponse(); + papeResponse.NistAssuranceLevel = NistAssuranceLevel.InsufficientForLevel1; + ProviderEndpoint.PendingAuthenticationRequest.AddResponseExtension(papeResponse); + } + + ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = true; + Debug.Assert(ProviderEndpoint.PendingAuthenticationRequest.IsResponseReady, "Setting authentication should be all that's necessary."); + ProviderEndpoint.PendingAuthenticationRequest.Response.Send(); + ProviderEndpoint.PendingAuthenticationRequest = null; + } + + protected void No_Click(object sender, EventArgs e) { + ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = false; + Debug.Assert(ProviderEndpoint.PendingAuthenticationRequest.IsResponseReady, "Setting authentication should be all that's necessary."); + ProviderEndpoint.PendingAuthenticationRequest.Response.Send(); + ProviderEndpoint.PendingAuthenticationRequest = null; + } + } +}
\ No newline at end of file |