Before starting this question, I must indicate that my knowledge of ASP.NET and C # is pretty much zero.
I am trying to integrate a version of CKFinder v3 in ASP.NET into a site created in a different language, and everything is going well so far; Everything is set up for me the way I want, and it works when I provide unlimited access to CKF, but I'm stuck now in trying to restrict access to it by authenticating only some members of my site to use it. All pages that appear CKFinder on my site are accessible only by some members, but I need an additional level of security if, for example, someone finds out a direct path to my file "ckfinder.html".
In the ASP version of CKFinder, I simply added this line to a function that checks my member privileges, where isEditor was a Boolean value that was assigned to each member based on information from my database:
session("accessckf")=isEditor
and then edited the CheckAuthentication() function in the CKFinder "config.asp" file to read:
function CheckAuthentication() CheckAuthentication=session("accessckf") end function
Reading through this “Howto,” authentication seems a lot more complicated in v3, but after a lot of trial and error and some help from Lesiman , I created this C # file, which is in my CKF directory:
<%@page codepage="65001" debug="true" language="c#" lcid="6153"%> <%@import namespace="CKSource.CKFinder.Connector.Core"%> <%@import namespace="CKSource.CKFinder.Connector.Core.Authentication"%> <%@import namespace="CKSource.CKFinder.Connector.Core.Builders"%> <%@import namespace="CKSource.CKFinder.Connector.Host.Owin"%> <%@import namespace="Owin"%> <%@import namespace="System.Data.Odbc"%> <%@import namespace="System.Threading"%> <%@import namespace="System.Threading.Tasks"%> <script runat="server"> public void Configuration(IAppBuilder appBuilder){ var connectorBuilder=ConfigureConnector(); var connector=connectorBuilder.Build(new OwinConnectorFactory()); appBuilder.Map("/path/to/connector",builder=>builder.UseConnector(connector)); } public ConnectorBuilder ConfigureConnector(){ var connectorBuilder=new ConnectorBuilder(); connectorBuilder.SetAuthenticator(new MyAuthenticator()); return connectorBuilder; } public class MyAuthenticator:IAuthenticator{ public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){ var domain=HttpContext.Current.Request.Url.Host; var cookie=HttpContext.Current.Request.Cookies[urlDomain]; var password=""; var username=""; var user=new User(false,null); if (cookie!=null){ if (cookie["username"]!=null) username=cookie["username"]; if (cookie["password"]!=null) password=cookie["password"]; if(username!=""&&password!=""){ var connection=new OdbcConnection("database=[database];driver=MySQL;pwd=[pwd];server=[server];uid=[uid];"); connection.Open(); OdbcDataReader records=new OdbcCommand("SELECT ISEDITOR FROM MEMBERS WHERE USERNAME='"+username+"' AND PASSWORD='"+password+"'",connection).ExecuteReader(); if(records.HasRows){ records.Read(); bool isEditor=records.GetString(0)=="1"; var roles="member"; if(isEditor) roles="editor,member"; user=new User(isEditor,roles.Split(',')); } records.Close(); connection.Close(); } } return Task.FromResult((IUser)user); } } </script>
Loading this page does not lead to errors (which does not necessarily mean that it works as an attempt to write something to the screen from the public class , for some reason it does not work), so now I'm at the stage of somehow checking the file’s authenticity .
I initially tried to download it via XMLHttp from my function, which checks the membership rights for the site, but, as I suspected, and how Lesmian confirmed that it would not work. After more trial and error, I added code to check the privileges of the site members on the C # file, which brings me to where I am now: stuck!
What do I need to change in CKFinder to use this user file for user authentication?