Beispiel #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="next">Next middleware</param>
 /// <param name="bo">options</param>
 /// <param name="signReader">Table prefix</param>
 /// <param name="action">action to execute after setted options</param>
 public DewBadgeMiddleware(RequestDelegate next, DewBadgeOptions bo, IDewBadgeSigner signReader, Action <HttpContext> action)
 {
     _next       = next;
     _bo         = bo;
     _signReader = signReader;
     _action     = action;
 }
Beispiel #2
0
        /// <summary>
        /// Builder method
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="badgeOptions">Badge options</param>
        /// <param name="action">Custom action to do after setted middleware options</param>
        /// <returns></returns>
        public static IApplicationBuilder UseBadgeMiddleware <T>(
            this IApplicationBuilder builder, DewBadgeOptions badgeOptions = null, Action <HttpContext> action = null) where T : class, IDewBadgeSigner, new()
        {
            T signer = new T();

            badgeOptions = badgeOptions ?? new DewBadgeOptions();
            return(builder.UseMiddleware <DewBadgeMiddleware>(badgeOptions, signer, action));
        }
Beispiel #3
0
        /// <summary>
        /// Return expired no auth
        /// </summary>
        /// <param name="options"></param>
        /// <param name="ctx"></param>
        public override void ResponseOnExpired(DewBadgeOptions options, ActionExecutingContext ctx)
        {
            var resp = new StandardResponse()
            {
                Error = new StandardResponseError("Badge expired, not authorized", 4)
            };

            ctx.Result = new JsonResult(new { Text = "Badge expired, not authorized", Error = "00004" })
            {
                StatusCode = 401
            };
        }
Beispiel #4
0
        /// <summary>
        /// Return result forbidden
        /// </summary>
        /// <param name="options"></param>
        /// <param name="ctx">httpcontext</param>
        /// <returns></returns>
        public override void ResponseOnForbidden(DewBadgeOptions options, ActionExecutingContext ctx)
        {
            var resp = new StandardResponse()
            {
                Error = new StandardResponseError("Forbidden resource", 3)
            };

            ctx.Result = new JsonResult(resp)
            {
                StatusCode = 403
            };
        }
Beispiel #5
0
        /// <summary>
        /// Return result no auth
        /// </summary>
        /// <param name="options"></param>
        /// <param name="ctx">httpcontext</param>
        /// <returns></returns>
        public override void ResponseOnError(DewBadgeOptions options, ActionExecutingContext ctx)
        {
            var resp = new StandardResponse()
            {
                Error = new StandardResponseError("Error on the resource", 2)
            };

            ctx.Result = new JsonResult(resp)
            {
                StatusCode = 400
            };
        }
Beispiel #6
0
        /// <summary>
        /// Return result on error
        /// </summary>
        /// <param name="options"></param>
        /// /// <param name="ctx">httpcontext</param>
        /// <returns></returns>
        public override void ResponseNoAuth(DewBadgeOptions options, ActionExecutingContext ctx)
        {
            var resp = new StandardResponse()
            {
                Error = new StandardResponseError("Not Authorized for the resource", 1)
            };

            ctx.Result = new JsonResult(resp)
            {
                StatusCode = 401
            };
        }
Beispiel #7
0
        /// <summary>
        /// Return expired no auth
        /// </summary>
        /// <param name="options"></param>
        /// <param name="ctx"></param>
        public virtual void ResponseOnExpired(DewBadgeOptions options, ActionExecutingContext ctx)
        {
            var opt = options as DewBadgeOptionsCookies;

            if (opt.EnableRedirect)
            {
                ctx.Result = new RedirectResult(opt.RedirectForbidden + "?fallbackurl=" + WebUtility.UrlEncode(ctx.HttpContext.Request.Path + ctx.HttpContext.Request.QueryString));
            }
            else
            {
                ctx.Result = new UnauthorizedResult();
            }
        }
Beispiel #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="next">Next middleware</param>
 /// <param name="bo">Connection string</param>
 /// <param name="signReader">Table prefix</param>
 public DewBadgeMiddleware(RequestDelegate next, DewBadgeOptions bo, IDewBadgeSigner signReader)
 {
     _next       = next;
     _bo         = bo;
     _signReader = signReader;
 }