mehtashail
Posts: 0
Joined: Tue Feb 04, 2014 1:29 am

SecurityContext failure to forward to login page

I am using a GenericSecurityContext for my app which I presume gets called with every service call being made if I select it for my service under Settings - SecurityContext.

Is there a way to automatically navigate to login page on failure if the service is not being run asynchronously?

Under GenericSecurityContext Service I see an Events tab that has Authorization Error, Login Success, Login Error. When do these get triggered and what can we do here? Can they be used for redirection?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

SecurityContext failure to forward to login page

Hello,

You can use navigate to page code on the service success event.
http://docs.appery.io/documentation/r...
http://docs.appery.io/documentation/j...

mehtashail
Posts: 0
Joined: Tue Feb 04, 2014 1:29 am

SecurityContext failure to forward to login page

I understand that for a normal REST Service but it seems different for the SecurityContext. Screenshot below. Can I specify the navigate script on on login or authorization error? What is the difference between authorization error and login error.

Image

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

SecurityContext failure to forward to login page

Hi Mehtashail.

Please clarify what do you mean by "SecurityContext". Please provide us with a screen shot.

The previous screen shot doesnot show the error.
Thus your service datasource will generate success event.

You have two ways to implement "logout" event.

1 Implement eventHandler function in JS asset and invoke it on every service success event.

2 Set up "generic security context" which implements this function described above. That's a more complex way, but more correct.

Also on your js action you should use something like:

pre
if(data.greeing == "Please log in first")
navigateTo("Screen21");/pre

Please let us know what way is preferrable for you.

mehtashail
Posts: 0
Joined: Tue Feb 04, 2014 1:29 am

SecurityContext failure to forward to login page

Hi Alena,
There is no error and you answered part of my question.

I am already implementing a generic security context. JS looks like this

code
Appery.Token = Appery .createClass(SecurityContext, {
invoke: function(service, settings) {
settings.headers['Authorization'] = "Bearer " + localStorage.getItem('access_token');
Appery.Token.$super.invoke.call(this, service, settings);
}

});
/code

If I understand what you are saying - this should be change as:
code
Appery.Token = Appery .createClass(SecurityContext, {
invoke: function(service, settings) {
settings.headers['Authorization'] = "Bearer " + localStorage.getItem('access_token');
Appery.Token.$super.invoke.call(this, service, settings);
if(data.msg == "Please log in first")
navigateTo("Login");

}

});
/code

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

SecurityContext failure to forward to login page

Mehtashail,

No, you should use code on success event http://docs.appery.io/documentation/w...

So look at this code:

pre
Appery.Token = Appery.createClass(SecurityContext, {

Code: Select all

 invoke: function(service, settings) { 
     var oldSuccess = settings.success; 
     var onSuccess = function(value, other){ 

         //here you should make your logout logic. For example. Uncomment it to test. 
         //if(value.msg == "Please log in first"){ 
         //    alert("LOGOUT"); 
         //    navigateTo("Login"); 
         //}; 

         oldSuccess.call(this, value, other); 
     }; 

     settings.success = onSuccess; 
     Appery.Token.$super.invoke.call(this, service, settings); 
 } 

});
/pre

Return to “Issues”