Question

I'm trying to develop a custom login form using Worklight customSecurityTest, based on SingleStepAuthAdapter application sample.

Basically, I've noticed that the login function used in the SingleStepAuthAdapater is always called after that user try to access to a secured function (after that, on login action, secured data are sent to the user), but if i try to call the submitAuthentication function directly, before any attempt to access to a secured function (i have inverted the "login page" with the "get secured data" page), i got the following error/lo on firebug:

enter image description here

The two POST calls are the same function raised two times by Worklight on login action (submitAuthentication function inside the SingleStepAuthAdapter called by singleStepAuthRealmChallengeHandler.submitAdapterAuthentication(invocationData, {})) and the error is related to the fact that authentication is requested twice: probably when the authentication request is performed, this function is issued twice after that the submitSuccess() function is called inside the handleChallenge (in fact, the issue doesn't occurs when i delete the submitSuccess invokation, but WL framework is not notified and, for example the isUserAuthenticated function return false, until the access to a secured resource is performed).

How can fix this behavior? What are the best practices to develop a simple login-form using worklight that allow authentication before any access to a proteced resource? I have found some workarounds (such as perform a fake data request before perform the submitAuthentication, but i hope that you can suggest me a better solution).

I've consulted the infocenter and the getting started modules, but probably due to my fault I'm not able to found any useful information

Was it helpful?

Solution

A common practice is to have an initial blank page or view for your app.

In WLCommonInit, either access a protected resource (that is what getsecretdata is all about), or call WL.Client.login(). Another option (suggested by @tk27) is to secure the app in the application descriptor and set connect on login to true. This will trigger authentication when the app starts.

Your challenge handler should display a login prompt dialog, and when the authentication successfully completes, transition to the first real page of your app.

This way, authentication is still done in response to a challenge from the WL Server (as it must be) but you don't see anything but a blank page to a login prompt until the login is successful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top