ChallengeResult.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Web;
  2. using System.Web.Mvc;
  3. using Microsoft.Owin.Security;
  4. namespace WeApp.Controllers.Results
  5. {
  6. public class ChallengeResult : HttpUnauthorizedResult
  7. {
  8. public ChallengeResult(string provider, string redirectUri)
  9. : this(provider, redirectUri, null)
  10. {
  11. }
  12. public ChallengeResult(string provider, string redirectUri, string userId)
  13. {
  14. LoginProvider = provider;
  15. RedirectUri = redirectUri;
  16. UserId = userId;
  17. }
  18. public string LoginProvider { get; set; }
  19. public string RedirectUri { get; set; }
  20. public string UserId { get; set; }
  21. public override void ExecuteResult(ControllerContext context)
  22. {
  23. var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
  24. if (UserId != null)
  25. {
  26. properties.Dictionary["XsrfId"] = UserId;
  27. }
  28. context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
  29. }
  30. }
  31. }