Ejemplo 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));
     };
 }
Ejemplo 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));
     };
 }
Ejemplo n.º 3
0
 private static RequestDelegate CreateModuleBeforeAfterHandler(BotwinModule module, (string verb, string path, RequestDelegate handler) route)
Ejemplo n.º 4
0
 private static Func <HttpRequest, HttpResponse, RouteData, Task> CreateModuleBeforeHandler(BotwinModule module, (string verb, string path, Func <HttpRequest, HttpResponse, RouteData, Task> handler) route)