Edgio

Working with Sessions in the JSON-RPC Interface

Origin Storage provides APIs that help you manage your session lifetime. For example, you can test to determine if your session has expired. You can also set your token to expire after a certain amount of time or never expire.
Session-related APIs are available in the JSON-RPC interface only.
The JSON-RPC interface provides these session-related methods:
Determine Your Token’s Age
Set Your Token’s Expiry

Determine Your Token’s Age

Method name: checkToken
Returns your token’s age in seconds. For example, if your token is set to expire at a known time and if your are running a series of time-consuming method calls, you can periodically call this method to determine if your token is approaching its end of life. If it is, you can re-authenticate (See Log In Using JSON-RPC and Log in Using the HTTP Interface, respectively.). Then continue with your method calls, thus ensuring that your calls will not fail due to an expired token.

Determine Token Age Using Named Parameters

JSON
1{
2 "method": "checkToken",
3 "id": 1,
4 "params": {
5 "token": "f2f12f31-49dd-434a-ae10-017a138349d5"
6 },
7 "jsonrpc": "2.0"
8}

Determine Token Age Using Positional Parameters

JSON
1{
2 "method": "checkToken",
3 "id": 1,
4 "params": [
5 "675b8d1a-45b1-487a-9396-4d240991600d"
6 ],
7 "jsonrpc": "2.0"
8}

Parameter Details

Parameter NameTypeDescription
tokenstrValid token from a call to login (JSON-RPC interface) or /account/login (HTTP interface). See Log In Using JSON-RPC and Log in Using the HTTP Interface, respectively.

Return Codes

  • 0: success
  • -10001: invalid token
For a list of error codes not specific to checkToken, see Global Error Codes.
On success returns an object with the following data:
  • age: (float) token’s age in seconds
  • code: (int) return code of the checkToken request; see Return Codes
  • gid: (int) group ID of user that created by token by logging in
  • path: (str) caller’s namespace.
  • uid: (int) user ID of user that created by token by logging in
  • username: (str) user name of user that created by token by logging in
Example:
JSON
1{
2 "uid": 12020,
3 "path": "/{Account name}",
4 "code": 0,
5 "gid": 100,
6 "age": 0.235221862793,
7 "username": "jvillarreal"
8}
On failure returns an object like the following, with code set to the appropriate value described in Return Codes:
JSON
1{
2 u'code': -10001
3}

Python Sample Requests

Check token:
Python
1>>> api.checkToken(token)
2{u'username': u'guest', u'code': 0, u'uid': 1020679, u'age': 18351.7339401, u'gid': 1086903, u'path': u'/{your Account name}'}

Set Your Token’s Expiry

Method name: updateSession
Sets your token to expire after a certain amount of time or sets it to never expire.
You can call updateSession only once per session. Calling the method more than once results in a -1 return code.

Set Token Expiry Using Named Parameters

Pass an expire time:
JSON
1{
2 "method": "updateSession",
3 "id": 1,
4 "params": {
5 "token": "a8068cf8-4cae-466c-b95a-6f578eb58604",
6 "expire": 7200
7 },
8 "jsonrpc": "2.0"
9}
Omit expire time, causing the token to never expire:
JSON
1{
2 "method": "updateSession",
3 "id": 4,
4 "params": {
5 "token": "d7a2bded-4e83-41ba-a712-40be4073c29f"
6 },
7"jsonrpc": "2.0"
8}

Set Token Expiry Using Positional Parameters

Positional parameters must be applied in the same order shown in the named parameters sample.
Pass an expire time:
JSON
1{
2 "method": "updateSession",
3 "id": 3,
4 "params": [
5 "d896310e-fb96-4e98-a892-eb11b31cfe3a"
6 ],
7 "jsonrpc": "2.0"
8}

Parameter Descriptions

Parameter NameTypeDescription
tokenstrValid token from a call to login (JSON-RPC interface) or /account/login (HTTP interface). See Log In Using JSON-RPC and Log in Using the HTTP Interface, respectively.
expireintOptional

Amount of time in seconds, after which your token will expire. To set your token to never expire, pass zero or pass only your token.

Defaults to 0.

Return Codes

  • 0: success
  • -1: session not updated or expiry already set
  • -34: invalid expiration
  • -10001: invalid token
For a list of error codes not specific to updateSession, see Global Error Codes.

Response Data

Returns only the codes discussed in Return Codes. Does not return any data structures.

Python Sample Requests

Set token to expire after two hours:
Python
1>>> api.updateSession(token, 7200)
20
Two options to set token to never expire:
Python
1>>> api.updateSession(token, 0)
20
3>>> api.updateSession(token)
40