diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-01-01 20:18:16 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-01-01 20:18:16 -0800 |
commit | 99c4550d70dc2b8402a7968c8066eb4c8468dc2b (patch) | |
tree | 3fae6c95d9d3d689d1fc673e31434897f4743d36 /projecttemplates/MvcRelyingParty/Controllers/AccountController.cs | |
parent | c0c1cfa4072375d0a3a75716144322084ab3b8cc (diff) | |
download | DotNetOpenAuth-99c4550d70dc2b8402a7968c8066eb4c8468dc2b.zip DotNetOpenAuth-99c4550d70dc2b8402a7968c8066eb4c8468dc2b.tar.gz DotNetOpenAuth-99c4550d70dc2b8402a7968c8066eb4c8468dc2b.tar.bz2 |
Added way for users to review the apps they've authorized and revoke permissions.
Diffstat (limited to 'projecttemplates/MvcRelyingParty/Controllers/AccountController.cs')
-rw-r--r-- | projecttemplates/MvcRelyingParty/Controllers/AccountController.cs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs index ed703ed..6d875b4 100644 --- a/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs +++ b/projecttemplates/MvcRelyingParty/Controllers/AccountController.cs @@ -226,11 +226,32 @@ } } + [Authorize, AcceptVerbs(HttpVerbs.Delete)] // ValidateAntiForgeryToken would be GREAT here, but it's not a FORM POST operation so that doesn't work. + public ActionResult RevokeToken(string token) { + if (String.IsNullOrEmpty(token)) { + throw new ArgumentNullException("token"); + } + + var tokenEntity = Database.DataContext.IssuedTokens.OfType<IssuedAccessToken>().Where(t => t.User.UserId == Database.LoggedInUser.UserId && t.Token == token).FirstOrDefault(); + if (tokenEntity == null) { + throw new ArgumentOutOfRangeException("id", "The logged in user does not have a token with this name to revoke."); + } + + Database.DataContext.DeleteObject(tokenEntity); + Database.DataContext.SaveChanges(); // make changes now so the model we fill up reflects the change + + return PartialView("AuthorizedApps", 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 }; var model = new AccountInfoModel { FirstName = Database.LoggedInUser.FirstName, LastName = Database.LoggedInUser.LastName, EmailAddress = Database.LoggedInUser.EmailAddress, + AuthorizedApps = authorizedApps.ToList(), }; return model; } |