/// <summary> /// Protected overriden method for authorizing user /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="password"></param> /// <param name="actionContext"></param> /// <returns></returns> protected override bool OnAuthorizeUser(BasicAuthenticationIdentity identity, HttpActionContext actionContext, out string invalidMsg) { UserServices userService = new UserServices(); // var provider = actionContext.ControllerContext.Configuration // .DependencyResolver.GetService(typeof(IUserServices)) as IUserServices; // if (provider != null) // { var userId = 0; if (identity.IsGuestUser) { userId = userService.AuthenticateGuest(identity.Name, identity.Password, out invalidMsg); } else { userId = userService.Authenticate(identity.Name, identity.Password, identity.SubscriptionTypeId, out invalidMsg); } var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity; if (invalidMsg.Length == 0) { if (basicAuthenticationIdentity != null) { basicAuthenticationIdentity.UserId = userId; } return(true); } else { basicAuthenticationIdentity.ErrorMessage = invalidMsg; return(false); } }
/// <summary> /// Virtual method.Can be overriden with the custom Authorization. /// </summary> /// <param name="user"></param> /// <param name="pass"></param> /// <param name="filterContext"></param> /// <returns></returns> protected virtual bool OnAuthorizeUser(BasicAuthenticationIdentity identity, HttpActionContext filterContext, out string invalidMsg) { invalidMsg = string.Empty; if (string.IsNullOrEmpty(identity.Name) || string.IsNullOrEmpty(identity.Password)) { return(false); } return(true); }