diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-03-13 17:20:24 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-03-13 17:20:24 -0800 |
commit | eff9b899606f4797b51a6e26b7fd3cf87bb57d15 (patch) | |
tree | 82327b29b2b3fd114eb21e723c76193e139a99f2 /projecttemplates/MvcRelyingParty/Code | |
parent | d197a28a898228296600c8b87b4f37301004c195 (diff) | |
parent | 514eb596a424c5ff29675053731b8ec550382cda (diff) | |
download | DotNetOpenAuth-eff9b899606f4797b51a6e26b7fd3cf87bb57d15.zip DotNetOpenAuth-eff9b899606f4797b51a6e26b7fd3cf87bb57d15.tar.gz DotNetOpenAuth-eff9b899606f4797b51a6e26b7fd3cf87bb57d15.tar.bz2 |
MVC RP project template now has the AJAX OpenID Selector.
Merge branch 'MVCselector' into v3.4
Diffstat (limited to 'projecttemplates/MvcRelyingParty/Code')
-rw-r--r-- | projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs b/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs index 2300e48..4501f52 100644 --- a/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs +++ b/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs @@ -3,13 +3,28 @@ using System.Collections.Generic; using System.Linq; using System.Web; + using System.Web.Mvc; + using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; + using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; using DotNetOpenAuth.OpenId.RelyingParty; public interface IOpenIdRelyingParty { - IAuthenticationRequest CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo); + Channel Channel { get; } + + IAuthenticationRequest CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy); + + IEnumerable<IAuthenticationRequest> CreateRequests(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy); + + ActionResult AjaxDiscovery(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy); + + string PreloadDiscoveryResults(Realm realm, Uri returnTo, Uri privacyPolicy, params Identifier[] identifiers); + + ActionResult ProcessAjaxOpenIdResponse(); IAuthenticationResponse GetResponse(); + + IAuthenticationResponse GetResponse(HttpRequestInfo request); } /// <summary> @@ -23,7 +38,7 @@ /// This is static because it is thread-safe and is more expensive /// to create than we want to run through for every single page request. /// </remarks> - private static OpenIdRelyingParty relyingParty = new OpenIdRelyingParty(); + private static OpenIdAjaxRelyingParty relyingParty = new OpenIdAjaxRelyingParty(); /// <summary> /// Initializes a new instance of the <see cref="OpenIdRelyingPartyService"/> class. @@ -33,14 +48,63 @@ #region IOpenIdRelyingParty Members - public IAuthenticationRequest CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo) { - return relyingParty.CreateRequest(userSuppliedIdentifier, realm, returnTo); + public Channel Channel { + get { return relyingParty.Channel; } + } + + public IAuthenticationRequest CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy) { + return this.CreateRequests(userSuppliedIdentifier, realm, returnTo, privacyPolicy).First(); + } + + public IEnumerable<IAuthenticationRequest> CreateRequests(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy) { + if (userSuppliedIdentifier == null) { + throw new ArgumentNullException("userSuppliedIdentifier"); + } + if (realm == null) { + throw new ArgumentNullException("realm"); + } + if (returnTo == null) { + throw new ArgumentNullException("returnTo"); + } + + var requests = relyingParty.CreateRequests(userSuppliedIdentifier, realm, returnTo); + + foreach (IAuthenticationRequest request in requests) { + // Ask for the user's email, not because we necessarily need it to do our work, + // but so we can display something meaningful to the user as their "username" + // when they log in with a PPID from Google, for example. + request.AddExtension(new ClaimsRequest { + Email = DemandLevel.Require, + FullName = DemandLevel.Request, + PolicyUrl = privacyPolicy, + }); + + yield return request; + } + } + + public ActionResult AjaxDiscovery(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy) { + return relyingParty.AsAjaxDiscoveryResult( + this.CreateRequests(userSuppliedIdentifier, realm, returnTo, privacyPolicy)).AsActionResult(); + } + + public string PreloadDiscoveryResults(Realm realm, Uri returnTo, Uri privacyPolicy, params Identifier[] identifiers) { + return relyingParty.AsAjaxPreloadedDiscoveryResult( + identifiers.Select(id => this.CreateRequests(id, realm, returnTo, privacyPolicy)).Flatten()); + } + + public ActionResult ProcessAjaxOpenIdResponse() { + return relyingParty.ProcessResponseFromPopup().AsActionResult(); } public IAuthenticationResponse GetResponse() { return relyingParty.GetResponse(); } + public IAuthenticationResponse GetResponse(HttpRequestInfo request) { + return relyingParty.GetResponse(request); + } + #endregion } } |