Trouble Authenticating User

Posted by Community Admin on 05-Aug-2018 11:09

Trouble Authenticating User

All Replies

Posted by Community Admin on 29-Jun-2011 00:00

I've been searching around the forums and the net for a way to essentially log in a user without having to enter the credentials in the log in page.
The setup we have is an existing site with our own users and roles and a separate Sitefinity web site. What I want to achieve is to seamlessly authenticate our existing users in Sitefinity.
So, I've implemented a service in the Sitefinity application that should log in the users. If they do not exist, I create a new one, settings the appropriate roles and then I try to authenticate the newly created user.

The users and roles are created and assigned as they should, but when authenticating the user, even when I get the UserLoggingReason.Success return code from the calls, that user is not logged in.
Calls to pages with specific view permissions set are "not served".

I looked at code posted in this post: http://www.sitefinity.com/devnet/forums/sitefinity-4-x/sdk/custom-authentication.aspx
and it looks like the code I wrote. What is it that I'm missing to make sure that the user is "really" logged in?
Do I need to call AuthenticateRequest? Do I need to set an authentication cookie?

I've also tried with calling the Users services, but to no avail.

Please help me.

Posted by Community Admin on 29-Jun-2011 00:00

Hello Anders,

Please check this forum post. If you use an older version of Sitefinity 4, please run a test using the latest version, because there are fixes related to the authentication.

Greetings,
Ivan Dimitrov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Posted by Community Admin on 29-Jun-2011 00:00

Hello Ivan,

I tried that too, but I have some questions about the code below:

using (var response = (HttpWebResponse)request.GetResponse())
  
            
  
   
  
                // HERE WE GET THE RESPONSE AND ADD THE COOKIES TO IT.
  
                cookies = response.Cookies;
  
                using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
  
                
  
                    // GET THE cookies AND ADD COOKIES NAME AND VALUE TO THE CURRENT RESPONSE!
  
                    var name = "";
  
                    var value = "";
  
                    Response.Cookies.Add(new HttpCookie(name, value));
  
                    return reader.ReadToEnd();
  
                
In the Response.Cookies.Add(new HttpCookie(name, value)); you pass an empty name and value. Shouldn't they be initialized with something first? Or should it be one of the cookies that are read earlier?

Also, I just upgraded to 4.1 SP2, no change.
.a

Posted by Community Admin on 29-Jun-2011 00:00

Hello Anders,

You can modify the code as below

// Invoke the method and return the response.
            using (var response = (HttpWebResponse)request.GetResponse())
           
                // Store the cookies from the response for the current session.
                cookies = response.Cookies;

                // Read the response
                using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
               
                    return reader.ReadToEnd();
               
           

The empty strings are left for some tests and if you want to pass the cookies from another storage where you need to set name and value and return the correct response.

Best wishes,
Ivan Dimitrov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

This thread is closed