It is possible to prolong an active session involving the XignSys SDK and the corresponding XignIn-Manager. This might
be necessary if the user needs more time to provide the necessary information, e.g., during the registration
process.
A session is created if the SDK establishes a connection to a XignIn-Manager. Depending on the configuration of the
corresponding XignIn-Manager, sessions may have a fixed maximum length and therefore prolonging may not be allowed
indefinitely. The point in time after which the session is invalidated is stored in the property lastRequestBefore in
the XignSession object. To prolong a session the function XignCommon.prolongSession(holder:) or its synchronous
counterpart can be invoked with the holder which represents the current session held by the XignSys SDK.
In order reduce the amount of session prolonging messages and to prevent a heartbeat like session handling, the
property nextRequestUntil within the XignSession gives information about the deadline before which a prolonging
attempt has to be made. As long as a prolonging request is received by the server before this point in time, the
session will be prolonged and the XignSession object itself is updated with the new data. Keep in mind though, that
prolonging a session requires a message to be sent to the XignIn-Manager, which may take some time due to network
latency. Therefore, prolonging a session should be triggered early enough to account for latency and slow networks but
not so early that the app constantly issues session updates.
The following example shows one way of how prolonging a session can be initiated. Beware though, that the values used for timeouts can be configured freely and are just recommendations.
private func updateSession(session: XignSession) {
let currentTime = Date()
let secondsUntilRequestIsDue: TimeInterval = currentTime.distance(to: session.nextRequestUntil)
// The minimum remaining session time in order to be able to trigger a session prolonging attempt.
let minimumRemainingSessionInSec: TimeInterval = 30.0
// Determine whether the sessions minimum remaining time should be ignored.
let ignoreMinimumRemainingSessionTime = false
// As soon as the remaining session time is less than this value an attempt to prolong the session should be
// performed.
let remainingSessionSecBeforeProlongingIsTriggered: TimeInterval = 60.0
// Refresh the session if the remaining session time is lies within certain borders - otherwise
// skip the prolonging and wait for the next check.
// Refresh the session if its remaining duration lies in the specified interval (normal case)
if (minimumRemainingSessionInSec...remainingSessionSecBeforeProlongingIsTriggered ~= secondsUntilRequestIsDue) {
XignSdk.shared.xignCommon.prolongSession(session)
}
// If the specified minimum remaining session
if (secondsUntilRequestIsDue < minimumRemainingSessionInSec) {
if (ignoreMinimumRemainingSessionTime) {
os_log(.info, "Prolonging session minimum time is ignored on purpose")
if (secondsUntilRequestIsDue < remainingSessionSecBeforeProlongingIsTriggered) {
XignSdk.shared.xignCommon.prolongSession(session)
}
} else {
os_log(
.error,
"Session is only valid for \(secondsUntilRequestIsDue) more seconds. Prolonging is not possible"
)
}
}
}
private fun updateSession(session: XignSession) {
val currentTime = Instant.now()
val secondsUntilRequestIsDue = Duration.between(currentTime, session.nextRequestUntil)
// The minimum remaining session time in order to be able to trigger a session prolonging attempt.
val minimumRemainingSessionInSec = Duration.ofSeconds(30)
// Determine whether the sessions minimum remaining time should be ignored.
val ignoreMinimumRemainingSessionTime = false
// As soon as the remaining session time is less than this value an attempt to prolong the session should be
// performed.
val remainingSessionSecBeforeProlongingIsTriggered = Duration.ofSeconds(60)
// Refresh the session if the remaining session time is lies within certain borders - otherwise
// skip the prolonging and wait for the next check.
// Refresh the session if its remaining duration lies in the specified interval (normal case)
if (secondsUntilRequestIsDue in minimumRemainingSessionInSec..remainingSessionSecBeforeProlongingIsTriggered) {
XignSdk.shared.xignCommon.prolongSession(session)
}
// If the specified minimum remaining session
if (secondsUntilRequestIsDue < minimumRemainingSessionInSec) {
if (ignoreMinimumRemainingSessionTime) {
Log.w("SessionProlonging", "Prolonging session minimum time is ignored on purpose")
if (secondsUntilRequestIsDue < remainingSessionSecBeforeProlongingIsTriggered) {
XignSdk.shared.xignCommon.prolongSession(session)
}
} else {
Log.e(
"SessionProlonging",
"Session is only valid for $secondsUntilRequestIsDue more seconds. " +
"Prolonging is not possible"
)
}
}
}