Veikedo

wsfed

Mar 14th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1.             services
  2.                 .AddAuthentication(options =>
  3.                 {
  4.                     options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  5.                     options.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
  6.                 })
  7.                 .AddCookie(options => options.Cookie.Name = "aspnetcorewsfed")
  8.                 .AddWsFederation(options =>
  9.                 {
  10.                     var settings = WebAppSettings.WsFederation;
  11.                     if (settings == null)
  12.                     {
  13.                         throw new InvalidOperationException("WsFederationSettings not set");
  14.                     }
  15.  
  16.                     options.MetadataAddress = settings.StsUrl + settings.MetadataPath;
  17.                     options.Wtrealm = settings.Realm;
  18.  
  19.                     options.Events.OnRedirectToIdentityProvider += context =>
  20.                     {
  21.                         if (context.Request.IsAjaxRequest())
  22.                         {
  23.                             context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
  24.                             context.HandleResponse();
  25.                         }
  26.  
  27.                         return Task.CompletedTask;
  28.                     };
  29.                 });
Advertisement
Add Comment
Please, Sign In to add comment