Esempio n. 1
0
 /// <summary>
 /// A way to require authentication for your <see cref="BotwinModule"/>
 /// </summary>
 /// <param name="module"><Current <see cref="BotwinModule"/>/param>
 public static void RequiresAuthentication(this BotwinModule module)
 {
     module.Before += context =>
     {
         var authenticated = context?.User?.Identity != null && context.User.Identity.IsAuthenticated;
         if (!authenticated)
         {
             context.Response.StatusCode = 401;
         }
         return(Task.FromResult(authenticated));
     };
 }
Esempio n. 2
0
 /// <summary>
 /// A way to require claims for your <see cref="BotwinModule"/>
 /// </summary>
 /// <param name="module">Current <see cref="BotwinModule"/></param>
 /// <param name="claims">The claims required for the routes in your <see cref="BotwinModule"/></param>
 public static void RequiresClaims(this BotwinModule module, params Predicate <Claim>[] claims)
 {
     module.RequiresAuthentication();
     module.Before += context =>
     {
         var validClaims = context.User != null && claims.All(context.User.HasClaim);
         if (!validClaims)
         {
             context.Response.StatusCode = 401;
         }
         return(Task.FromResult(validClaims));
     };
 }
Esempio n. 3
0
 private static RequestDelegate CreateModuleBeforeAfterHandler(BotwinModule module, (string verb, string path, RequestDelegate handler) route)
Esempio n. 4
0
 private static Func <HttpRequest, HttpResponse, RouteData, Task> CreateModuleBeforeHandler(BotwinModule module, (string verb, string path, Func <HttpRequest, HttpResponse, RouteData, Task> handler) route)