SimpleSession
This scoped class provides methods for managing the current session.
The constructors used for creating an instance of the scoped SimpleSession object are not available. Use the ss.getSession() method instead.
getClientIP()
Use this method to return the field value containing the IP-address of the client.
Return:
| Type | Description |
|---|---|
| String | This method returns the IP address value by default. It returns null if there are no IP values. |
Example:
getClientIP()
const session = ss.getSession();
const ipAddress = session.getClientIP();
ss.info(ipAddress); // Info: 127.0.0.1
rotateToken()
Use this method to receive a new authorization token for the current session.
To receive a new token, the following conditions must be met:
- The session user is authenticated.
- The current token has not expired.
- The remaining time to live of the token does not exceed the value of the simple.session.token_rotation_window system property (3600 seconds by default).
If any of the conditions is not met, the method throws an exception.
Return:
| Type | Description |
|---|---|
| String | The method returns a new authorization token. |
Example:
rotateToken()
(function (request, response) {
let session = ss.getSession();
try {
let token = session.rotateToken();
response.setBody({
"token": token
});
} catch (e) {
response.setBody({
"error": e.message
});
}
})(SimpleApiRequest, SimpleApiResponse)