Boosting Security: The Power of Short Tokens in Authentication

Niluka Sripali Monnankulama
Many Minds
Published in
6 min readDec 27, 2023

When it comes to designing your OAuth system, one crucial decision is determining how long access tokens should last. Interestingly, the OAuth specifications don’t provide extensive guidance on token lifetimes. The reason? It’s because the ideal duration depends on the specific nature of what you’re building.

In simpler terms, you have the flexibility to set the expiration time for access tokens based on your project’s unique requirements. This decision should align with the balance between security and usability that best suits your application. So, whether you opt for shorter or longer lifetimes, the key is to tailor it to the needs of your OAuth implementation.

Speeding Things Up in OAuth: Why Access Token Lookups Matter

Picture this: If every access token needs a check at the authorization server every time, things could get really slow. It’s like needing permission repeatedly, causing delays in your system.

Making OAuth Smarter with JWTs: Quick and Easy!

When tweaking your OAuth system, pick JSON Web Tokens (JWTs) for your access tokens — it’s like finding a golden shortcut. Why? Because you only have to look at the token itself to decide if it’s good for processing an API request.

Why’s that cool? Well, it means you don’t have to check a network or database every time there’s an API request. By putting all the important info straight into the token, you make your authentication checks fast and smooth. This keeps your system quick and responsive, ensuring things run smoothly without unnecessary waits.

Striking the Right Balance: Understanding Access Token Validation

Let’s break it down. Checking access tokens just by looking at the token itself is quick and convenient. But here’s the deal: if you only rely on the token and don’t cross-verify from the outside during its entire validity period, there’s a small catch.

The token might become invalid before its expiration time. It’s a bit like trusting a timer without occasionally glancing at the clock. So, while you gain speed by skipping extra checks, be mindful of the chance that the token could lose its validity a bit earlier than expected. It’s like walking a tightrope between moving fast and ensuring everything stays on course.

Locking In Security: Why Short-Token Lifetimes Matter

Imagine token lifetimes as timers you control. If you want to minimize the chances of things going wrong in your system when checking access tokens, go for short lifetimes.

In plain words, if you’re serious about making your system super secure, keep access token lifetimes short. It’s like setting a quick alarm for added protection — less time for potential issues, more peace of mind for you.

Swift Security: The Logic Behind Short Token Lifetimes

Here’s the deal: if your access token lifetimes are super short — let’s say just 10 minutes — it means there’s, at most, a 10-minute window where an API could mistakenly accept an access token that should have been invalidated. This could happen if, for instance, a user or application was deleted.

In simpler terms, short lifetimes reduce the time an access token could cause trouble after it should have been turned off. It’s like closing the door quickly to minimize the chance of someone slipping in after they’re supposed to be out.

Boosting Security with Short Access Token Lifetimes: Why It Matters

Short access token lifetimes not only speed up security but also minimize the risk if a token gets into the wrong hands.

Access tokens can leak in various ways — a desktop app saving a token on disk, a different app accessing it, a vulnerability in a web app, or even your APIs unintentionally logging tokens in an unknown file. With short lifetimes, the exposure time is limited, reducing the potential damage if a token is compromised. It’s like closing a window of opportunity for unauthorized access, adding an extra layer of protection to your system.

Playing it Safe: Token Lifetimes and Security

When deciding how long your tokens should last, think about the risk of them ending up in the wrong hands. Here’s the deal: unlimited tokens? Pretty risky.

To lower the chance of leaks and the risk of APIs doing local checks, go for shorter token lifetimes. It’s like putting on an extra safety lock, making sure your system stays secure and sound. So, when in doubt, choose shorter lifetimes for a safer setup.

In this blog post, I will provide a step-by-step guide on how users can customize the default token expiration time within the WSO2 environment. The process involves altering configurations to suit specific requirements, ensuring a more tailored and secure experience.

01. Changing the default token expiration time at the global-level

To change the default token expiration time at the global level in WSO2, you can modify the deployment.toml configuration file. Follow the instructions below:

  1. Locate the deployment.toml file:
  • The deployment.toml file is typically found in the <WSO2_HOME>/repository/conf/ directory.

2. Open deployment.toml for editing:

  • Use a text editor to open the deployment.toml file.

3. Add or modify the token expiration configurations:

  • Changing the default expiration time of the application access tokens
[oauth.token_validation]
app_access_token_validity = 1800

Definition: Application access tokens are tokens that authenticate an application rather than a specific user.

Default Validity Period: This is the time, usually measured in seconds, for which an application access token is considered valid by default. Which is set to 60 minutes by default in WSO2.

Usage: Application access tokens are often used by applications to access APIs on behalf of the application itself, rather than a specific user. The validity period determines how long the application can continue to make authorized requests.

  • Changing the default expiration time of user access tokens
[oauth.token_validation]
user_access_token_validity = 1800

Definition: User access tokens are tokens that authenticate a specific user and grant access to their resources.

Default Validity Period: This is the time, typically in seconds, for which a user access token remains valid by default. which is set to 60 minutes by default in WSO2.

Usage: User access tokens are employed when a user logs in or authorizes an application. The token allows the application to access specific resources on behalf of the user. The validity period sets the time window during which the token is considered valid for making authorized requests.

  • Changing the default expiration time of refresh tokens
[oauth.token_validation]
refresh_token_validity = 86400
  • Definition: Refresh tokens are long-lived tokens that are used to obtain new access tokens without requiring the user to re-authenticate.
  • Default Validity Period: The default expiration time for refresh tokens varies across implementations. It is the period during which a refresh token remains valid, allowing its usage to obtain new access tokens. which is set to 24 hours by default in WSO2
  • Usage: Refresh tokens are typically used in scenarios where long-term access is needed, and the user doesn’t want to log in frequently. Changing the default expiration time allows customization based on security and operational requirements.

Finally, your configuration will look as follows if you have configured all the above configurations:.

[oauth.token_validation]
app_access_token_validity = 1800
user_access_token_validity = 1800
refresh_token_validity = 86400

Note : The changes that you make here will be applied only to the new applications that you create.

02. Changing the default token expiration time at the application-level ( WSO2 Identity Server)

Here are the general steps to modify the default token expiration time for an OAuth application:

  1. Log in to the WSO2 Identity Server Console: Open a web browser and navigate to the WSO2 Identity Server Management Console. Log in with your administrator credentials.
  2. Access the OAuth Application List:
  • In the left sidebar, navigate to “Application” -> “+New Application” Or Select the Desired OAuth Application

3. Navigate to the “Protocol” Tab:

  • Look for the “OAuth/OpenID Connect ” Configuration in the Standard-Based Application settings.

4. Modify Token Expiration Settings:

  • Within the “OAuth/OpenID Connect ” section, you should find settings related to token expiration, including
  • “User Access Token Expiry Time,”
  • “Application Access Token Expiry Time,”
  • and “Refresh Token Expiry Time.”
  • Update the values for the desired token expiration times according to your requirements.

5. Save the Changes:

  • After making the necessary changes, save the configuration.

To sum it up, short tokens are like a secret weapon for keeping data safe. This blog has shown you why they’re crucial in the world of cybersecurity, offering valuable insights for organizations aiming to strengthen their defenses.

I’ve even shared a practical example using the WSO2 Identity Server to make it more real.

Thanks…..

--

--

Niluka Sripali Monnankulama
Many Minds

An IT professional with over 7+ years of experience. Member of the WSO2 Identity & Access Management Team.