Session
The REST API from webPDF is a “stateful API”, i.e. a session is created when an access token is created in the context of an authorization with authentication.
The session is associated with the access token and exists as long as the token is valid (timeout) or the token is actively invalidated by a logout.
The session contains the "document storage" (storage) on the server to store the documents to be processed between each web service call.
Expiration time (timeout)
In the REST API, each granted access token is assigned a session that has a specific expiration time (timeout) based on the access token. The session expiration time is supplied as an expiresIn in the response structure to an authentication/user/login.
curl -X POST -i -H 'Accept: application/json' -H 'Authorization: Basic YWRtaW46YWRtaW4=' http://localhost:8080/webPDF/rest/authentication/user/login
HTTP/1.1 200
Cache-Control: no-cache, no-store, no-transform, proxy-revalidate, max-age=0
Content-Type: application/json
Content-Length: 44
{
"expiresIn": 3599,
"token": "eyJraWQiOiJyb3ZZTFQ4TXgwcTd1WW1i ... CO2TLHCiQCsuMf-1Vw",
"refreshToken": ""
}
It is specified in seconds at the time the access token is issued, i.e. in the above example the session will expire in 3599 seconds.
End session with logout
If a session is logged out or expires (timeout), it ends at once: its documents can no longer be reached and are deleted. An access token of the local login becomes invalid; tokens of an external provider stay valid and open a new, empty session (see below). With a Redis/Valkey document storage on an SMB share or a shared local folder, the files are not deleted automatically.
A token is only accepted as long as its session exists. After a logout, after the session has expired, or after a restart of a server that keeps its sessions in its local session storage, an access token or refresh token issued for that session is rejected with the error code -9009 (WEBSERVICE_SESSION_TOKEN_REVOKED); web service calls then answer with HTTP 401. Log in again to continue. This also applies to an access token that is passed as bearer token to the SOAP web services. Access tokens issued by an external OAuth2 provider are not affected: such a token opens a new, empty session with a new ID on its next use; no document of the ended session is available in it.
A session ends at once and for good when it is logged out or when an administrator closes it. With a Redis/Valkey session storage, the session is marked as ended in Redis/Valkey before its deletion is queued, so no request reaches it afterwards on any node, even while its documents are still being deleted. An expired session is not marked: every node recognizes the expiry from the stored end time, so in a cluster the end is only as simultaneous as the clocks of the nodes. The session is deleted all the same, and no new document can be stored in it once its deletion has begun. No token brings an ended session back to life, a refresh token included. After the end, a request is answered as follows:
| Request | Answer |
|---|---|
| Access token of the local login (REST) | HTTP 401, -9009 |
| Access token of the local login as bearer token (SOAP) | SOAP fault with -9009 |
| Refresh token of the local login | HTTP 400, -9009 |
| Token that has expired by itself | HTTP 401, -9002 |
A request that is still storing documents when its session ends is aborted with -60 (WEBSERVICE_SESSION_TOKEN_NOT_FOUND) and HTTP 400; nothing is left behind. This applies to a single server and to a cluster.
curl -X GET -i -H 'Accept: application/json' -H 'Authorization: Bearer eyJraWQiOiJyb3ZZTFQ4TXgwcTd1WW1i ... CO2TLHCiQCsuMf-1Vw' http://localhost:8080/webPDF/rest/authentication/user/logout
You should always call a logout after a login, and after all operations performed, to end the session and thus avoid unnecessary memory consumption.
Extend session
To prevent a session from expiring, the access token must be renewed before the session expires. This requires another token, the Refresh Token. By using the refresh token, the session is extended and a new access token with a new expiration time (timeout) and a new refresh token are created. From this point on, only the new refresh token can be used for a further session extension: a refresh token can be redeemed only once, and only while its session exists. A refresh works only on a running session: once the session has expired - also in the moment before the server has removed it - or has ended, it is rejected and does not bring the session back. A refresh token that has already been exchanged for a new one, or whose session has ended (logout, expiration, server restart with a local session storage), is rejected with the error code -9009 (WEBSERVICE_SESSION_TOKEN_REVOKED) and HTTP status 400; log in again in this case. The previous access token remains valid until its own expiration time; use the new one.
In a cluster, these checks take full effect once all nodes run version 10.0.7 or later.
To receive a refresh token, it must be actively requested during authentication.
Refresh tokens can only be used if they are issued by the local authorization of the webPDF server. Refresh tokens that originate from an OAuth2 provider, for example, cannot be used. In this case, call the corresponding interface of the OAuth2 provider to obtain a new access token. Use this new token in the webPDF Web Services authorization, which then automatically renews the session when the new token is used.