Max Session Timeout
#
ProblemAn application developer may want to force a sign out or terminate a session after N
hours regardless of activity. This is known as Maximum Session Timeout and is common for applications with particular session rules. However, the Okta dashboard only provides a configuration for Maximum Idle Session Timeout as shown below.
#
SolutionWhile Okta does not support this setting within the admin dashboard, this can be configured through the Policy APIs. The documentation for this setting can be found on the Sign On Session Object.
#
OverviewWith the APIs create a policy to contain a rule with an actions.signon.session.maxSessionLifetimeMinutes
configured.
The API sequence is as followed:
Create Policy > Create Rule > Update Rule with maxSessionLifeTime
Create Policy
Create Rule for Policy with Max Session Timeout
In addition, it's worth noting that the admin dashboard can be used to create the policy and rule followed with a PUT
request to update the rule with the maxSessionLifetimeMinutes
.
This approach requires a few additional steps to get the associated IDs:
Get Policy ID with "Get all Policies by type" > Get Rule Id with "Get Policy Rules"
Update Existing Rule with Max Session Lifetime
#
Node.js ScriptThe working code sample below can be used for reference or as a script.
#
Try it yourselfYou can use the REPL below to execute the script without the need of setting up any additional environments or tools, simply update the environment variables and configure the settings.
#
DiscussionWhen setting the rule the maxSessionLifetimeMinutes
, Okta expects the maxSessionIdleMinutes
to be set to equal or lesser than the sessionlifetime minutes.
#
CreditsCredit to Sudipto Desmukh for providing this solution, his original write up can be found on his blog and Brandon Him for the write-up and sample script.