I am using web / mobile sdk (js). But my app is not a single page application. So i must login with XPMobileSDK.Login every page. Therefore I want to once login on server side and XMobileSDK using this Token / Ticket etc. is it possible ? is there any examples ?
Problem Summary: without Username and Password promt, I have to write / inject inside my javascript file. So this is high security vulnerability.
Unfortunately there is no example @Said Ay. But the good news is that you can work around the problem using XMobileSDK .connectWithId() .
In order to use the command you need to connect to the mobile server using XMobileSDK.Connect() . On the respond you will receive a token named
<Param Name="ConnectionId" Value="fb6f686c-29e3-4c3c-b4e9-8e4256d9ae9c"/>
You needs to store this value somewhere where you can re-use in on the next page (cookie, local storage etc.). When the user is on the next page (where no connect/login is made) you can use XMobileSDK .connectWithId() to automatically continue the session that was started on the previous page with no need to connect and login again. The declaration of that method is located in WebClient /XPMobileSDK/Lib/Connection.js
/**
* Connects to the server with an existing connectionId.
*
* @method connectWithId
* @param {String} server: url of the server to connect to
* @param {String} connectionId: token provided from external login request
*/
this.connectWithId = function (server, connectionId) {
self.server = server;
self.connectionId = connectionId;
console.log('Connecting with Id ' + self.connectionId);
setState(XPMobileSDK.library.ConnectionStates.connecting);
// We need to check the connection ID we have been provided with the server. Easiest way is to just ping it
self.sendLiveMessage();
// we set a flag which is checked when the live message comes back. If it contains an OK response we set the connection as live.
// If it contains a time out response we set it as disconnected
self.connectingViaExternalConnectionID = true;
};
You can check how server is taken on the initialize method of the same class.
I hope that helps.
Thank for reply. But my problem is slightly different this. I have an asp.net backend for connect or login.
Controller example:
And pass this ConnectionId with XPMobileSDK.connectWithId(url, connectionId);
It is observer:
var observer = {
connectionDidConnect: connectionDidConnect,
connectionDidLogIn: connectionDidLogIn
};
But I didn’t list the cameras.
And console log is:
In my opinion, it was because I did not log in. But there is not ‘LoginWithId’ ?
@Teodor Hadjistoyanov do you have any idea ?
@Said Ay I am on sick leave this week. I asked my colleagues if they can help you.
Hi Said,
I’ve tried something similar (connect and login from .NET based app and perform connectWithId() with already received connectionId).
I receive however different error code - 19 - Security error.
In order to overcome that I’ve disabled chap security:
Connection = new Connection(connectionType, _address, UInt32.Parse(_port));
Connection.CommandsQueueing = CommandsQueueing.SendDirect;
Connection.ChapSecurityEnabled = false;
After that I was able to do connectWithId successfully.
please bear in mind that it is good idea to keep connection alive in your back-end during whole live of the front-end.
@Teodor Hadjistoyanov get well soon. Thanks @Petar Vutov I had also reached the same thing.