B4J Question jRDC2: How to pass SessionId (or Type) between remote server & client?

Widget

Well-Known Member
Licensed User
Longtime User
My app will have the user enter a UserName/PW from my B4A app before he can connect to the remote database. When the remote server authenticates the user as being valid (by using UserName_PW table), a session id is generated and a row is added to a temporary table on the server showing the user is connected and authenticated. The remote server then needs to pass this session id back to the client.

The session id can be a string or part of a Type. Passing a Type back and forth would be better because I could pass more info.

Server to Client:
1) Should I modify the DBResult Type and add another string variable to hold the SessionId? Or is there a Tag I could use that gets passed to the remote server automatically?

Client to Server:
2) The client app also needs to pass this same session id back to the remote server on every request so the server knows the user has been previously authenticated so it will allow access to the database. I don't see a simple way to pass the session id (or type) from the client back to the remote server. I suppose I could pass it as a query parameter that gets removed before any SQL is executed on the server but I am hoping there is a better way.

Does anyone have any ideas?
TIA
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You don't really need to send anything yourself.

This is a good use case for HttpSessions. Once the user authenticates:
B4X:
req.GetSession.SetAttribute("authenticated", True)

Check for authentication:
B4X:
If req.GetSession.GetAttribute2("authenticated", False) = False Then
   Log("Not authenticated!")
   Return
End If
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
Erel,
I did not realize there was a map available to store session variables (state). It is just what I was looking for. You made my day. :D
I will read up on it tomorrow. Thanks.
 
Upvote 0

Diceman

Active Member
Licensed User
Check for authentication:
B4X:
If req.GetSession.GetAttribute2("authenticated", False) = False Then
   Log("Not authenticated!")
   Return
End If

How do I use HttpSessions.GetAttribute2() in the client app? I don't see any reference to HttpSessions in the client.
TIA
 
Upvote 0
Top