public bool Authorize(DashboardContext dashboardContext)
        {
            var context = dashboardContext.GetHttpContext();

            string header = context.Request.Headers["Authorization"];

            if (string.IsNullOrWhiteSpace(header) == false)
            {
                AuthenticationHeaderValue authValues = AuthenticationHeaderValue.Parse(header);

                if ("Basic".Equals(authValues.Scheme, StringComparison.InvariantCultureIgnoreCase))
                {
                    string parameter = Encoding.UTF8.GetString(Convert.FromBase64String(authValues.Parameter));
                    var    parts     = parameter.Split(':');

                    if (parts.Length > 1)
                    {
                        string username = parts[0];
                        string password = parts[1];

                        if ((string.IsNullOrWhiteSpace(username) == false) && (string.IsNullOrWhiteSpace(password) == false))
                        {
                            return(Users.Any(user => user.Validate(username, password)) || Challenge(context));
                        }
                    }
                }
            }

            return(Challenge(context));
        }
コード例 #2
0
        public bool Authorize(Hangfire.Dashboard.DashboardContext context)
        {
            var httpContext = context.GetHttpContext();

            return(httpContext.User.Identity.IsAuthenticated &&
                   httpContext.User.IsInRole("admin"));
        }
コード例 #3
0
 public bool Authorize(DashboardContext context)
 {
     var httpContext = context.GetHttpContext();
     return httpContext.User.IsUserType(UserType.SiteAdmin);
 }