You are viewing limited content. For full access, please sign in.

Question

Question

Login using Windows Authentication

asked on November 7, 2015 Show version history

I tried using below code from Laserfiche SDK 9.0 help file but not working. Am I missing any line of code?

 

To create a connection using Windows authentication, do not specify a user name or password when calling the LogIn() function. In the following example, we attempt to log into a repository using Windows authentication.

RA [C#]

// Using the Server object to retrieve list of repositories
Server myServ = new Server("MyServerName");
RepositoryRegistrationCollection repoRegColl = myServ.GetRepositories();
RepositoryRegistration myRepoReg = repoRegColl["MyRepositoryName"];
Session mySess = new Session();
mySess.LogIn(myRepoReg); // Use current thread's Windows credentials.

 

0 0

Replies

replied on November 7, 2015

If you know the server name and repository you can hard code them when you instantiate the RepositoryRegistration object.  To streamline code you can also instantiate the RepositoryRegistration object inside of the Session connect method .  Here is a code snippet that will create a new session object and login using Windows authentication;

Session raSession = new Session[];

raSession.Connect(new RepositoryRegistration("SERVERNAME", "REPOSITORYNAME"));
raSession.LogIn();

 

0 0
replied on November 9, 2015

Cliff's suggestions are good improvements, but there isn't anything wrong with your code that would prevent it from working.  What error are you receiving?  If this is in a web application, the situation is more complicated, see this question.

0 0
replied on November 9, 2015

it says access denied

0 0
replied on November 10, 2015

Can this user log in through the Client? If this application is running as a service, keep in mind it will use the service login, not the current Windows user.

0 0
replied on November 17, 2015

yes this user can log in to client. I am not using service. I am trying it into web application.

0 0
replied on November 18, 2015

See Brian's post above.

0 0
replied on November 24, 2015

I tried with Logon user function and it is working but it requires password also. How do I have user's password. How it is working with SharePoint Windows Authentication mode? Provide me some good post which has correct information for Windows Authentication.

0 0
replied on November 24, 2015

There are a few things you need to take into consideration when trying to do SSO through IIS. First and foremost, the browser will not pass the credentials to the server if the url is not considered to be on the intranet. For example, if you have a web address of "https://webserver.domain.local/login.aspx" then the browser will not send the credentials to the server. This article outlines it pretty well. It says only Internet Explorer, but it is the same for all browsers. There are a few more things to consider, but this one ate my lunch.

0 0
replied on November 24, 2015 Show version history

I am focusing on this code:

 

RA [C#]

// Using the Server object to retrieve list of repositories
Server myServ = new Server("MyServerName");
RepositoryRegistrationCollection repoRegColl = myServ.GetRepositories();
RepositoryRegistration myRepoReg = repoRegColl["MyRepositoryName"];
Session mySess = new Session();
mySess.LogIn(myRepoReg); // Use current thread's Windows credentials.

Here it is mentioned that without username and password it will check for windows credentials then why it is not working. Browser related changes I need to do for all users. If you open SharePoint Site with Laserfiche webparts then we do not require to set anything.

 

I am trying the above code in SharePoint but it is not working where my site is already enabled for Windows Authentication.

 

I need a working code to Login using Windows Authentication.

0 0
replied on November 30, 2015

Normally you do not want to use the current thread's Windows credentials, since the host process is running as a low-trust local account.  Have you read the thread I linked to in my initial response?  Your code does no impersonating.  Is Kerberos correctly configured?

0 0
replied on November 30, 2015

And if you are running under SharePoint, it may be more complicated.  You may find that the Identity you get from the user's context is not a WindowsIdentity, but is a ClaimsIdentity instead.  I believe there is a setting on your SharePoint site that controls which one you get.  The WindowsIdentity is easier to work with, otherwise you need to convert the ClaimsIdentity to a WindowsIdentity, by calling into the C2WTS service via the S4U library.  This identity only works with Kerberos constrained delegation, and you also need to grant access to the C2WTS service.  You should check out the documentation for the Web Access SharePoint integration.

0 0
replied on November 30, 2015

Let me find out the document and check it. You can send me link for the updated document, if you have.

0 0
replied on December 1, 2015 Show version history

I also tried the code:

try
{
   var current = System.Security.Principal.WindowsIdentity.GetCurrent();
   WindowsIdentity clientID = (WindowsIdentity)HttpContext.Current.User.Identity;
   using (wic = clientID.Impersonate()) {
      // Log into Repository
      RepositoryRegistration MyRepository = new RepositoryRegistration(servername, reponame);
      Session newsession = new Session();               
      newsession.LogIn(MyRepository);
      MySession = newsession;
   }
}

catch (Exception e)
{
   error = e.Message;
}

 

but it is also not getting validated.

0 0
replied on December 1, 2015 Show version history

Have you trusted the machine for delegation so that Kerberos will work properly?  That is a requirement.

0 0
replied on December 1, 2015

how to do that?

0 0
replied on December 2, 2015

This is covered in the link I posted in my first answer to this question, the one dated November 9th.  There is also a lot of information on the support site: https://support.laserfiche.com/search/SearchWF.aspx?q=kerberos

0 0
replied on December 2, 2015

Thanks

I am writing my own SharePoint Web Part using SDK. My SharePoint site has Laserfiche Prebuilt Web Parts and it does not asks for login or other settings. We haven't done any settings on server for Laserfiche and SharePoint.

 

So do you think while writing a custom Web Part using SDK, I need to do these settings?

0 0
replied on December 4, 2015

It's a reasonable assumption, but if you don't verify that your environment satisfies your requirements then you won't be sure that it's not the cause of your errors.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.