06. VBAuth Token Lifetime Management

VBAuth

Security White Paper Series

Paper 6: Token Lifetime Management — Caching, Renewal, and What Each Approach Holds in Memory

This edition accompanies the VBAuth full feature demo database released 07/09/2026. The two approaches it describes are VBA-side and work with any released version of VBAuth.

Peter Bryant — Corylus Business Systems | Andrew Richards — The IT Service Ltd

This is the sixth paper in the VBAuth security series. The earlier papers established why delegated permissions are the only safe model for Access applications calling the Microsoft Graph API, how endpoint-scoped app registrations give precise control over permissions and audit events, and how app roles restrict access to sensitive operations. This paper addresses a different set of decisions: how token lifetime is managed within a session, what each approach holds in memory, and how to choose the right approach for a given deployment.

This paper is factual and technical in character. Its purpose is to ensure that developers — and those responsible for evaluating VBAuth in security-conscious environments — understand what each approach holds in memory, for how long, and what that means in practice. It assumes a working knowledge of VBAuth and a basic familiarity with OAuth 2.0 concepts. Readers new to either should begin with the earlier papers in this series.

1. The Token Lifecycle — A Shared Frame of Reference

When a VBAuth feature is triggered, the DLL presents the user with a Microsoft Entra ID login prompt. On successful authentication, Microsoft issues a bearer token — a signed string that the calling code presents to the Graph API to prove it is authorised to act on behalf of the authenticated user. Bearer tokens have a finite lifetime, set by Microsoft, of approximately 60 to 90 minutes.

VBAuth uses delegated permissions throughout. The user must be present and authenticated; the DLL never acts without a signed-in user. Application permissions — which would allow background calls without a user — are not used and are not supported.

When the bearer token expires, the application must obtain a new one. How it does so — and what it holds in memory in the process — is the subject of this paper.

2. Two Approaches to Token Lifetime

Two approaches are available today. The first is VBAuth’s default behaviour and needs no configuration. The second is implemented in the calling application rather than in the DLL, and is demonstrated in the full feature demo database — where it applies to the session as a whole rather than to individual registrations. A third, silent renewal through the DLL, is in development and is outlined at 2.3.

2.1 Re-authenticate on Expiry

This is the default behaviour in all versions of VBAuth and requires no configuration. When the bearer token expires — or when the Entra app registration or permission scopes have changed since the token was issued — the next call to the DLL triggers a full interactive authentication prompt. The user signs in again, a new bearer token is issued, and the call proceeds.

In this approach the DLL is entirely stateless between calls. No token material of any kind persists after the call completes. MSAL’s internal app object goes out of scope and is eligible for garbage collection; the cache it held goes with it.

This approach is appropriate for applications with elevated permission scopes, for deployments in environments where explicit re-authentication is a policy requirement, or for any context in which the developer prefers the simplest possible security model.

2.2 VBA-Level In-Memory Caching

Demonstrated in the VBAuth complete demo database, this approach holds bearer tokens in VBA memory within the host application for their natural lifetime, so that a token acquired once can serve later calls without returning to the DLL.

It is not a single on-or-off cache. AcquireBearerToken works through five steps in order and stops at the first that can supply a valid token.

StepWhat it reusesCondition
1The token already in handSame registration, unexpired, and the requested scopes match the cached scopes exactly
2The token already in handSame registration, unexpired, and the requested scopes are covered by the cached scopes
3This feature’s own cached tokenAn unexpired token previously acquired for this AppID, on the same registration
4Another feature’s cached tokenAn unexpired token acquired for a different AppID on the same registration, whose scopes cover the request
5Nothing — the DLL is calledNo cached token satisfies the request; interactive authentication follows

Steps 1 and 2 read the token currently in hand, held in module-level variables. Steps 3 and 4 read tknCache, an array sized at run time from the rows in lclVBAuthAdmin, holding one entry per AppID: the decoded bearer token, its UTC expiry, the ClientID and TenantID it was acquired for, and its normalised scope claims.

All five steps run in production. The demo database exposes them as four selectable levels through the Select Caching Level control on the feature form, so that each level can be demonstrated in isolation.

LevelSwitches setSteps active
No caching – always authnone5 only
Current token onlyblnCheckExistingToken1, 2 and 5
Current token or cached rowplus blnUseRowCache1 to 3, and 5
Current token or any cacheplus blnUseFullCache1 to 5

After every call, strTokenSource reports which step supplied the token, displayed on the form; where step 4 was used, intTokenSourceAppID holds the AppID whose cached token was reused and its value appears inside that message. These are a teaching aid: they make the cache visible while a developer is learning it, and are not required by the mechanism.

Two properties of this design matter for security, and both are deliberate.

Every reuse path tests ClientID and TenantID before it tests scopes. A token is never reused across registrations or across tenants, whatever the scopes say.

Step 4 is the one to understand before enabling it. It allows a token acquired for one feature to serve a different feature — but only where both use the same app registration, and only where the cached token’s scopes already cover the request. The consent grant, the sign-in audit event and any Conditional Access policy all belong to the registration rather than to the individual feature, so reuse within a registration changes nothing about what was consented to or what was recorded. Reuse across registrations is deliberately not implemented, for exactly that reason, and the omission is documented in the AcquireBearerToken header.

Within the 60 to 90 minute token lifetime, this approach involves no refresh token anywhere. The cache holds bearer tokens, their expiry times, and the registration and scopes each belongs to. When a token expires, the next call falls through to step 5 and the user authenticates again.

ClearTokenCache empties both the array and the variables holding the token currently in hand. It is a local clear only: it does not touch MSAL, so where the browser session is still live the next sign-in may complete without re-prompting for credentials.

2.3 A Third Approach, In Development

Silent renewal is in development for a future release. It will extend an authenticated session beyond the initial bearer token lifetime without prompting the user, using a refresh token held inside MSAL’s in-memory cache within the DLL’s process memory and never accessible to VBA code.

It is outlined here rather than omitted because it changes the shape of the model in this paper: a third approach brings a third memory profile and a third set of trade-offs. It will be documented in full — configuration, what it holds in memory, and when it is and is not appropriate — in the edition of this paper that accompanies the release. Nothing described in this paper changes to accommodate it; the two approaches above continue to behave exactly as set out.

2.4 Persistent Token Caching

MSAL supports an optional persistent token cache, protected at rest using the Windows Data Protection API (DPAPI), which would survive application restarts and carry a sign-in from one session into the next. VBAuth does not implement this, and does not intend to.

That decision, the reasoning behind it, and the alternatives Microsoft provides are set out in Paper 7: Sign-In Persistence. It is a longer answer than belongs here, and a different question from the one this paper addresses: this paper is about what happens within a session; Paper 7 is about what happens between them.

3. What Each Approach Holds in Memory

The table below summarises what each approach holds in memory, at what point, and for how long. Both approaches share the same behaviour during an active call — a bearer token exists in process memory for the duration of the call. The differences arise in what persists between calls.

Re-auth on ExpiryVBA-Level Cache
Bearer token — during callIn process memoryIn process memory
Bearer token — between callsNot heldIn VBA memory until expiry: the token in hand, and one entry per AppID in tknCache
Refresh tokenNot heldNot held
MSAL app objectCreated per call, then garbage collectedCreated per call, then garbage collected
Written to diskNothingNothing
Session behaviourInteractive prompt on expiry or scope changeSilent within token lifetime; interactive prompt after
Cross-feature reuseNoneOnly at level 4, and only within one registration
Default stateAlways onOff — the three switches default to False

4. Choosing the Right Approach for Your Deployment

There is no single correct answer. The right approach depends on the permission scopes the application uses, the session patterns of its users, and the security requirements of the environment into which it is deployed. The following questions provide a framework for making that decision.

What permission scopes does the application use?

Lower-risk scopes — Mail.Send, Calendars.ReadWrite, and similar — are well suited to VBA-level caching. The session experience is smooth and the in-memory footprint is modest. Higher-risk scopes — those granting broad read or write access across the tenant — warrant more conservative treatment. Re-authentication on expiry keeps the session window bounded and explicit.

What are the session control requirements of the environment?

Some environments — regulated industries, high-security internal tooling — have explicit requirements around session duration and re-authentication frequency. Where those requirements exist, re-authentication on expiry is the appropriate choice regardless of scope. Where they do not, the developer has discretion.

What is the expected working pattern of the end user?

A user who opens the application, completes a single task and closes it has little to gain from caching — the initial token lifetime is more than sufficient. A user who works across several features in one session benefits materially: without caching, each feature on a separate registration means a separate authentication prompt.

Should one feature’s token serve another?

This is the question level 4 asks, and it deserves a deliberate answer rather than a default. Where several features share an app registration and one has already acquired a token whose scopes cover another’s needs, level 4 will reuse it and no second prompt appears. That is efficient and it is bounded by the registration. A developer who would rather each feature acquire its own token — for clearer audit events per feature, or simply for a more conservative posture — should select level 3 instead, which keeps each AppID to its own cached token.

5. Summary Reference

ApproachWhat it holds in memorySession behaviourWell suited to
Re-auth on expiryBearer token during call only. Nothing between calls.Interactive prompt when the token expires or scopes change.Elevated scopes; strict session control requirements; the simplest security model.
VBA-level cacheBearer tokens in VBA memory until expiry, one per AppID plus the token in hand. No refresh token.Silent within the token lifetime; interactive prompt after.Most desktop deployments; a good balance of user experience and memory footprint.

This series was prepared with AI assistance. The technical content has been reviewed and verified by the authors.

VBAuth, developed and maintained by Andrew Richards (The IT Service Ltd) and Peter Bryant (Corylus Business Systems), © 2025–2026. All rights reserved. https://vbauth.com

Updated on September 7, 2026