Authentication in JS

Hi there

I am doing some tests using the SDK and trying to set up a very basic HTML frontend using RemObjectsSDK.js

I have 2 services. The “Login” service (functions Login & Logout) that has RequireSession=False.

ROJSONMessage.SessionIdAsId=True

  1. When (successfully) login I create a session (Self.CreateSession) in my code. This (and also Logout) works fine. Is it correct that it is the HTML/JS client that “proposes” a SessionId ?

  2. On the client side I then want to query the second sevice (function Sum) that has RequireSession=True. This however will send a fresh/new SessionId. How do I use the authenticated SessionId from before? How do I access/read/specify it?

Thx & Cheers,
P.

  1. Yes. Message object in its constructor creates new GUID and assigns it to clientID.
  2. Just use the same message object for both login and main service.

You could put login procedure into onLoginNeeded handler:
channel.onLoginNeeded = function (aCallback) {
var loginService = new LoginService(channel, message, “LoginService”);
loginService.Login(“john”, “john”, function(result) {
if (aCallback)
aCallback();
}, RemObjects.UTIL.showError);
});
}

Also to persist between page reloads, session id could be stored in browser cookies.

var message = new RemObjects.SDK.BinMessage();
var clientID = getCookie(“ROClientID”);
if (clientID) message.setClientID(clientID);

Ooops, my fault.
I was using a separate channel & message for each service.
Sorry about that.

Thx & cheers,
Peter