Page 1 of 1

Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 9:28 am
by dev-ws-011
Hi,

I have encountered incorrect behavior of security.authenticate() which always returns null in developer irrespective of credentials are valid or not.

Here is my code snippet:
Code: Select all
function onSolutionOpen(arg, queryParams) {
   var loginResult = security.authenticate(["username","password"]);
   application.output("Login Result:"+loginResult,LOGGINGLEVEL.INFO);
   if(loginResult){
      var userName = security.getUserName();
      application.output("User name:"+userName,LOGGINGLEVEL.INFO);
   }
   else
   {
      application.output("Login failed due to invalid credentials.",LOGGINGLEVEL.INFO);
      application.exit();
   }
}


Output of above code:
Login Result:
Login failed due to invalid credentials.

Note:
Code is tested for both valid and invalid credentials but same result. and also tested on Servoy 8.2 & Servoy 8.4 but same result. :(

Any assistance in resolving above will be highly appreciated.

Thanks

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 11:07 am
by sanneke
I see you are using the string "username" and "password". I guess you wanted to use the dataproviders?
Code: Select all
var loginResult = security.authenticate([username,password]);

Regards Sanneke

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 11:19 am
by dev-ws-011
sanneke wrote:I see you are using the string "username" and "password". I guess you wanted to use the dataproviders?
Code: Select all
var loginResult = security.authenticate([username,password]);

Regards Sanneke


Thanks Sanneke for assistance. I have tried with dataproviders as well, but it didn't work. Also, we can pass string as I have done in code as mentioned in Servoy Documentation.

If there is any other solution please let me know.

Thanks

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 11:25 am
by sanneke
You could check the user and password:
Code: Select all
var user_id = security.getUserUID(username);
var loginResult = false
if(user_id ){
   loginResult  = security.checkPassword(user_id, password)
}
if(loginResult){
      var userName = security.getUserName();
        security.login(username,user_id ,["users"])
      application.output("User name:"+userName,LOGGINGLEVEL.INFO);
   }
   else
   {
      application.output("Login failed due to invalid credentials.",LOGGINGLEVEL.INFO);
      application.exit();
   }

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 11:30 am
by sanneke
I did a quick test in developer, but it seems to work fine for me. Are you sure your user does exist in here:

security.jpg
security.jpg (119.55 KiB) Viewed 4548 times

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 11:43 am
by dev-ws-011
sanneke wrote:I did a quick test in developer, but it seems to work fine for me. Are you sure your user does exist in here:

security.jpg


Yes I have tried with valid user which is present in User and group security.

Are you able to run my code snippet successfully in developer?

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 11:55 am
by sanneke
Yes I am:

code_snippet.jpg
code_snippet.jpg (196.37 KiB) Viewed 4542 times


One thing that I noticed while trying this, when you create a user, it seems his password is 'password' but you really have to click into the field and change it to 'password'. Maybe that is what is missing?

password.jpg
password.jpg (153.69 KiB) Viewed 4542 times

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 1:05 pm
by dev-ws-011
Yes, I have updated password field to 'password'.

I have tried code which you have mentioned in above comments to use security.login(). Here is my summary when tried using security.login():
1. Used Smart Client, Servoy v8.4 & v6.1.6, false is returned (username & password are valid).
2. Used Web Client, Servoy v8.4 & v6.1.6, true is returned i.e. Successful.

Security.authenticate() is having same results as previous i.e. returning null.

Can you please mention which Servoy version you are using and which client you have used to test the code?

Thanks.

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 1:19 pm
by sanneke
I see, we have found the problem. I was trying in 8.4 NG.

Authenticate for smart client will only work in an authentication module. In smart client the idea is that you have your solution, a login module and an authentication module. The client first will only download the login module. This login module will talk to the authentication module that runs only on the server. If the authentication module authenticates, the client can download the solution. This way he will not have the solution if he is not a valid user.

Here is more info about the process in the smart client:
https://wiki.servoy.com/display/DOCS/Im ... entication

You can also use a easy solution where you just check the property 'must authenticate' on the solution properties and servoy will give its own login form.

Re: Security.authenticate() always returns null in developer

PostPosted: Tue Apr 16, 2019 2:23 pm
by dev-ws-011
Thanks Sanneke.

You assistance is highly appreciated in resolving the issue. I will explore teh documnet link whcih you have shared.

Thanks once again.