ibm mobilefirst - Attaching cookie to WorkLight Adapter response header -
i developing mobile app using worklight 5.0.6 , attach secure cookie response returned adapter.
we not using worklight authentication realm because not wish "bind" session specific wl server in clustered production environment. authenticate session calling sign-on adapter authenticates user details against end system. part of response sign-on adapter call create secure cookie (http only) containing authenticated information , attach response returned sign-on adapter. cookie should included in header subsequent adapter made application call server.
regards,
tom.
i suggest trying create custom worklight authenticator communicates backend. documentation custom authenticator can found here:
to answer question, here how approach without using custom authenticator:
- make adapter call authenticate client
function authenticate(username, password){
var invocationdata = { adapter : 'authenticationadapter', procedure : 'authenticate', parameters : [username, password] }; wl.client.invokeprocedure(invocationdata, { onsuccess : authsuccess, onfailure : authfailure });
}
- get cookie response on client side , save (i suggest saving using jsonstore can encrypt saved cookie)
function authsuccess(response){ console.log("auth success"); var mycookie = response.invocationresult.responseheaders.cookiename // save cookie somehow }
- on subsequent adapter calls, send cookie client along each request
function adapterrequestforprotectedresource(){
var mysecurecookie = getmycookiefromlocalstorage();
var invocationdata = { adapter : 'protectedresourceadapter', procedure : 'getresource', parameters : [mysecurecookie] }; wl.client.invokeprocedure(invocationdata, { onsuccess : success, onfailure : failure });
}
on adapter, set cookie in header
function getresource(securecookie) {
// secure cookie must of form: "cookiename=cookievalue" var input = { method : 'get', returnedcontenttype : 'json', path : "/resource", headers: {"cookie": securecookie} }; return wl.server.invokehttp(input);
}
Comments
Post a Comment