summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--projecttemplates/MvcRelyingParty/Content/Site.css10
-rw-r--r--projecttemplates/MvcRelyingParty/Content/images/infocard_23x16.pngbin0 -> 810 bytes
-rw-r--r--projecttemplates/MvcRelyingParty/Content/images/openid_login.gifbin0 -> 237 bytes
-rw-r--r--projecttemplates/MvcRelyingParty/Controllers/AccountController.cs41
-rw-r--r--projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs3
-rw-r--r--projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj3
-rw-r--r--projecttemplates/MvcRelyingParty/Views/Account/AuthenticationTokens.ascx20
-rw-r--r--projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx6
8 files changed, 81 insertions, 2 deletions
diff --git a/projecttemplates/MvcRelyingParty/Content/Site.css b/projecttemplates/MvcRelyingParty/Content/Site.css
index 59aeb2e..3bf2268 100644
--- a/projecttemplates/MvcRelyingParty/Content/Site.css
+++ b/projecttemplates/MvcRelyingParty/Content/Site.css
@@ -315,3 +315,13 @@ div#title
font-weight: bold;
color: #ff0000;
}
+
+ul.AuthTokens li.OpenID
+{
+ list-style-image: url(../../content/images/openid_login.gif);
+}
+
+ul.AuthTokens li.InfoCard
+{
+ list-style-image: url(../../content/images/infocard_23x16.png);
+}
diff --git a/projecttemplates/MvcRelyingParty/Content/images/infocard_23x16.png b/projecttemplates/MvcRelyingParty/Content/images/infocard_23x16.png
new file mode 100644
index 0000000..9dbea9f
--- /dev/null
+++ b/projecttemplates/MvcRelyingParty/Content/images/infocard_23x16.png
Binary files differ
diff --git a/projecttemplates/MvcRelyingParty/Content/images/openid_login.gif b/projecttemplates/MvcRelyingParty/Content/images/openid_login.gif
new file mode 100644
index 0000000..cde836c
--- /dev/null
+++ b/projecttemplates/MvcRelyingParty/Content/images/openid_login.gif
Binary files differ
diff --git a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs
index 6d875b4..0fa8a9a 100644
--- a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs
+++ b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs
@@ -98,7 +98,7 @@
ModelState.AddModelError("OpenID", ex.Message);
}
} else {
- ModelState.AddModelError("OpenID", "This doesn't look like a valid OpenID.");
+ ModelState.AddModelError("openid_identifier", "This doesn't look like a valid OpenID.");
}
return View();
@@ -243,15 +243,54 @@
return PartialView("AuthorizedApps", GetAccountInfoModel());
}
+ [Authorize, AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
+ public ActionResult AddAuthenticationTokenReturnTo(string openid_identifier) {
+ var response = this.RelyingParty.GetResponse();
+ if (response != null) {
+ switch (response.Status) {
+ case AuthenticationStatus.Authenticated:
+ Database.LoggedInUser.AuthenticationTokens.Add(new AuthenticationToken {
+ ClaimedIdentifier = response.ClaimedIdentifier,
+ FriendlyIdentifier = response.FriendlyIdentifierForDisplay,
+ });
+ Database.DataContext.SaveChanges();
+ break;
+ default:
+ break;
+ }
+ }
+
+ return RedirectToAction("Edit");
+ }
+
+ [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateAntiForgeryToken]
+ public ActionResult AddAuthenticationToken(string openid_identifier) {
+ Identifier userSuppliedIdentifier;
+ if (Identifier.TryParse(openid_identifier, out userSuppliedIdentifier)) {
+ try {
+ var request = this.RelyingParty.CreateRequest(userSuppliedIdentifier, Realm.AutoDetect, Url.ActionFull("AddAuthenticationTokenReturnTo"));
+ return request.RedirectingResponse.AsActionResult();
+ } catch (ProtocolException ex) {
+ ModelState.AddModelError("openid_identifier", ex);
+ }
+ } else {
+ ModelState.AddModelError("openid_identifier", "This doesn't look like a valid OpenID.");
+ }
+
+ return View("Edit", GetAccountInfoModel());
+ }
+
private static AccountInfoModel GetAccountInfoModel() {
var authorizedApps = from token in Database.DataContext.IssuedTokens.OfType<IssuedAccessToken>()
where token.User.UserId == Database.LoggedInUser.UserId
select new AccountInfoModel.AuthorizedApp { AppName = token.Consumer.Name, Token = token.Token };
+ Database.LoggedInUser.AuthenticationTokens.Load();
var model = new AccountInfoModel {
FirstName = Database.LoggedInUser.FirstName,
LastName = Database.LoggedInUser.LastName,
EmailAddress = Database.LoggedInUser.EmailAddress,
AuthorizedApps = authorizedApps.ToList(),
+ AuthenticationTokens = Database.LoggedInUser.AuthenticationTokens.ToList(),
};
return model;
}
diff --git a/projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs b/projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs
index fbd0ae7..787b8df 100644
--- a/projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs
+++ b/projecttemplates/MvcRelyingParty/Models/AccountInfoModel.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
+ using RelyingPartyLogic;
public class AccountInfoModel {
public string FirstName { get; set; }
@@ -13,6 +14,8 @@
public IList<AuthorizedApp> AuthorizedApps { get; set; }
+ public IList<AuthenticationToken> AuthenticationTokens { get; set; }
+
public class AuthorizedApp {
public string Token { get; set; }
diff --git a/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj b/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj
index 4c9dab7..a4604e5 100644
--- a/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj
+++ b/projecttemplates/MvcRelyingParty/MvcRelyingParty.csproj
@@ -125,7 +125,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <Content Include="Content\images\infocard_23x16.png" />
+ <Content Include="Content\images\openid_login.gif" />
<Content Include="OAuth.ashx" />
+ <Content Include="Views\Account\AuthenticationTokens.ascx" />
<Content Include="Views\Account\Authorize.aspx" />
<Content Include="Views\Account\AuthorizeApproved.aspx" />
<Content Include="Views\Account\AuthorizedApps.ascx" />
diff --git a/projecttemplates/MvcRelyingParty/Views/Account/AuthenticationTokens.ascx b/projecttemplates/MvcRelyingParty/Views/Account/AuthenticationTokens.ascx
new file mode 100644
index 0000000..9632988
--- /dev/null
+++ b/projecttemplates/MvcRelyingParty/Views/Account/AuthenticationTokens.ascx
@@ -0,0 +1,20 @@
+<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcRelyingParty.Models.AccountInfoModel>" %>
+<h3>
+ Login methods
+</h3>
+<ul class="AuthTokens">
+<% foreach(var token in Model.AuthenticationTokens) { %>
+ <li class="<%= token.IsInfoCard ? "InfoCard" : "OpenID" %>" title="<%= Html.Encode(token.ClaimedIdentifier) %>">
+ <%= Html.Encode(token.FriendlyIdentifier) %>
+ </li>
+<% } %>
+</ul>
+
+<h4>Add a new login method </h4>
+<% using(Html.BeginForm("AddAuthenticationToken", "Account", FormMethod.Post)) { %>
+ <%= Html.AntiForgeryToken() %>
+ <label for="openid_identifier">OpenID:</label>
+ <%= Html.TextBox("openid_identifier")%>
+ <%= Html.ValidationMessage("openid_identifier")%>
+ <input type="submit" value="Add token" />
+<% } %> \ No newline at end of file
diff --git a/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx b/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx
index e1a1872..09635f2 100644
--- a/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx
+++ b/projecttemplates/MvcRelyingParty/Views/Account/Edit.aspx
@@ -23,9 +23,13 @@
</div>
<input type="submit" value="Save" />
<span id="updatingMessage" style="display: none">Saving...</span>
+ <% } %>
<div id="authorizedApps">
<% Html.RenderPartial("AuthorizedApps"); %>
</div>
- <% } %>
+
+ <div id="authenticationTokens">
+ <% Html.RenderPartial("AuthenticationTokens"); %>
+ </div>
</asp:Content>