/pySessions

Pulggable middleware written on python to manage web sessions by using tokens

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

pySessions

Pulggable middleware written on python to manage web sessions by using tokens

This simple code block can be pulgged at any where in your exsisting / new projects. This can handle your users active session details with ease.

The most generic part of the session handling is globalized in this package

HOW TO USE

IMPORT AND INITIALIZE

create an instance of authenticator in your project start

from pySessions.authenticator import Authenticator
authenticator  =  Authenticator(unique_key=<uniquekey>,timeout=10000)

The unique may be any like your app name or some random key.

METHODS

To create a session

authenticator.manage(<key>)

The key can be userid or any unique value

it returns

{
"session_id": "b48cb6a2f8648741a71b4f27a670cbaa",
 "status": "success",
 "timeout": 1588381679
}

timeout -> genrated time + default timeout given at obj intialization

To validate a session


authenticator.validate(<session_id>)

The key can be userid or any unique value

it returns


{

 "status": "success",

 "valid": true

}

valid -> contains the session is valid (true) or not valid (false)

List of active sessions

authenticator.active_sessions(<id>)

id -> key used to create sessions

it returns

"active_sessions": [
    {
      "session_id": "9ab74f78ba1cb80b3b97e719ab5ea618",
      "time_ms": 1588382179,
      "user": <userid>
    },
    {
      "session_id": "6a6a65f09710e8853cfcf49b668edb78",
      "time_ms": 1588382180,
      "user": <userid>
    }
  ],
  "status": "success",
  "user_id": <userid>

To destory/blacklist/block sessions

authenticator.block(<session_id>)

This removes that session from the memory

this returns

 {
 "status": "success",
 "deleted":true
 "session_id":<session_id>
 }

The status in all api responses determines the succesfull excecution of the commands