Exemplo n.º 1
0
        /// <summary>
        /// Show username and token stored in database
        /// </summary>
        /// <returns></returns>
        public JsonResult ShowAuthenticationValues()
        {
            JsonResult json = null;

            using (var googleService = _authorize.Authorize())
            {
                json = Json(_authorize.ResponseCredentials(), JsonRequestBehavior.AllowGet);
            }

            return(json);
        }
Exemplo n.º 2
0
 public string GetInformation(string name, string pass)
 {
     if (authorize.Authorize(name, pass))
     {
         return("Secret information");
     }
     return("Not authorized");
 }
Exemplo n.º 3
0
 public bool HasAccess(
     string path,
     string username,
     string[] roles,
     AccessType type)
 {
     return(_authorize?.Authorize(path, username, roles, type) ?? true);
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel();

            kernel.Bind <IAuthorize>().To <FacebookAuthenticationProvider>();
            kernel.Bind <IDbConnection>().To <DbConnection>();

            IAuthorize authorize = kernel.Get <IAuthorize>();

            var isAuthorized = authorize.Authorize("mojLogin", "mojeHaslo");
        }
Exemplo n.º 5
0
 public ActionResult LogOn(LogOnViewModel logOn)
 {
     if (authentication.Authorize(logOn.Username, logOn.Password))
     {
         return(Redirect(logOn.ReturnUrl));
     }
     else
     {
         ModelState.AddModelError("", "Invalid credentials.");
     }
     return(View());
 }
Exemplo n.º 6
0
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken,
                                             RequestHandlerDelegate <TResponse> next)
        {
            if (!await _authorize.Authorize(request))
            {
                _logger.LogWarning("User is not authorized {user}", request.User?.GetIdentity());
                return(Result.Forbidden.ConvertTo <TResponse>());
            }

            var response = await next();

            return(response);
        }
Exemplo n.º 7
0
        protected virtual bool Authorize()
        {
            if (IsPostBack)
            {
                return(true);
            }
            bool hasAccess = false;
            bool hasAttr   = false;

            foreach (object at in GetType().GetCustomAttributes(true))
            {
                IAuthorize auth = at as IAuthorize;
                if (auth != null)
                {
                    hasAttr = true;
                    if (auth.Authorize(this.Context))
                    {
                        hasAccess = true;
                    }
                }
            }

            if (hasAccess)
            {
                return(true);
            }

            if (!hasAttr)
            {
                string sitmap = HttpContext.Current.Server.MapPath("~/Web.sitemap");
                if (File.Exists(sitmap))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(sitmap);

                    foreach (XmlNode childNode in doc.DocumentElement.FirstChild.ChildNodes)
                    {
                        if (childNode.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (FindNodeAndCheckAccess(childNode, "Menu", false))
                        {
                            return(true);
                        }
                    }
                }
            }
            FormsAuthentication.RedirectToLoginPage();
            return(false);
        }