Token Lifetimes and Logout in OIDC: Short Access Tokens, Refresh Token Rotation, Concurrent Refresh and Back-Channel Logout
The hours after login: why access tokens should be short, why refresh tokens belong outside the browser, why users get logged out at random once rotation is on, and how to end the provider session on logout.
In an application that signs users in with OIDC, most mistakes are not made at login. They are made in the hours after it. How long should the access token live, where should the refresh token sit, and what exactly should end when the user clicks "log out"? Wrong answers to these questions come back either as security holes or as bugs that log users out at random moments and are hard to reproduce. This post lays out how to design token lifetimes and logout correctly from the start.
Separate the layers first: there are three sessions
A typical OIDC setup runs three independent lifetimes at once:
The identity provider session. Once the user signs in at the provider, the provider sets its own cookie. This is where single sign-on comes from: moving to another application does not ask for a password.
The application's own session. After exchanging the code for tokens at the callback, the application usually opens its own session cookie.
Token lifetimes. The access token, the refresh token and the ID token each have their own expiry.
Most bugs come from treating these as one thing. The classic case: on logout the application deletes only its own cookie. When the user clicks "sign in" again, the provider session is still alive, so they are let straight back in without a password. To the user the logout button is broken; on a shared computer it is a real security problem.
Access tokens: keep them short, do not rely on revocation
If the access token is a signed JWT, the resource server accepts it by checking the signature and exp without asking the provider. That is fast, but it has a cost: there is no standard way to take back an issued JWT. Disable the user, reset their password, and the token still works until it expires.
You have two options:
Short-lived JWTs. Somewhere between 5 and 15 minutes is a common choice. The revocation delay is at most that long. This is the right default for most applications.
Opaque tokens with introspection (RFC 7662). The resource server asks the provider about the token on every request, or with a short cache. Revocation is immediate, but every request now depends on the provider, and when the provider slows down the whole API slows down.
My position: start with short-lived JWTs. Move to introspection only on surfaces that truly need instant revocation, such as money movement or admin actions. Letting access tokens live for an hour or a day and saying "we will revoke if needed" means building a system you cannot actually revoke in.
Do not forget clock skew during validation. A few seconds of drift between servers is enough for a freshly minted token to fail its iat or nbf check. Most libraries offer a leeway setting; 30 to 60 seconds is plenty. A larger leeway gives back what the short lifetime bought you.
Refresh tokens: this is the valuable one
With short access tokens, the refresh token is what keeps the user signed in. It is also what an attacker actually wants, because it can mint new access tokens for weeks. Two decisions matter most.
Where it lives. In a browser single page application, putting the refresh token in localStorage means any script that makes it onto the page can read it. Current guidance is the Backend for Frontend pattern: tokens stay on the server, and the browser only carries a session cookie marked HttpOnly, Secure and SameSite. This layer forwards API calls and attaches the token. It is one more component, but having no tokens in the browser at all shrinks the attack surface dramatically.
Rotation. The OAuth security best current practice (RFC 9700) asks that refresh tokens for public clients (browser, mobile, desktop) be either sender-constrained (DPoP, RFC 9449, or mTLS) or rotated on every use. With rotation, each refresh returns a new refresh token and invalidates the old one. If the provider sees an old token being reused, it treats this as a sign of theft and revokes the whole chain derived from it.
Rotation's own trap: concurrent refresh
Almost every team that enables rotation hits the same problem: users get logged out occasionally, with no obvious pattern. The cause is usually this. The access token has expired, the application fires three API calls at once, all three get a 401, and all three try to refresh with the same refresh token. The first one wins and rotates the token. The other two use what is now an old token, the provider sees reuse and revokes the chain. The same happens with several tabs open.
The fix lives on both sides.
On the client, collapse refreshes into a single flight: only one refresh request goes out at a time, and everyone else waits for its result.
let refreshing: Promise<string> | null = null;
async function getAccessToken(): Promise<string> {
if (!isExpired(current)) return current.accessToken;
if (!refreshing) {
refreshing = refreshTokens().finally(() => { refreshing = null; });
}
return refreshing;
}
That is not enough across tabs, because each tab has its own memory. In the browser, the Web Locks API (navigator.locks.request) gives you a single lock across tabs. With a Backend for Frontend the problem moves to the server and is solved with a per-session lock there, which is one more reason to use that pattern.
On the provider side, if your product supports it, allow a reuse window of a few seconds for the previous token. It rescues a duplicated request that arrived late over the network, but keep it short or rotation stops protecting anything.
Logout: three mechanisms that do different jobs
RP-Initiated Logout. After closing its own session, the application redirects the user to the end_session_endpoint from the provider's discovery document:
GET {end_session_endpoint}
?id_token_hint={id_token received at login}
&post_logout_redirect_uri=https://app.example.com/logged-out
&state={random value}
The provider ends its session and sends the user back. The post_logout_redirect_uri must be registered on the client in advance, or the provider will refuse the redirect. You also need to keep the ID token from login. Many teams discard it after validation and have no id_token_hint left at logout time.
Back-Channel Logout. When the user logs out from another application or directly at the provider, the provider sends a server-to-server POST to your application. The body contains a signed JWT called logout_token. When validating it, check the signature, iss, aud and iat, that the events claim contains the key http://schemas.openid.net/event/backchannel-logout, that at least one of sid or sub is present, and that there is no nonce. Once it passes, end the matching local sessions and return 200.
The step people skip: to know which local session to end, you must have stored the sid from the ID token in your own session record at login. If sessions live only in a signed cookie with nothing on the server, the back-channel call arrives and there is nothing to close. If you want this mechanism, pick your session store accordingly.
Front-Channel Logout. The provider's logout page loads each application's logout URL in a hidden iframe. Because browsers now restrict third-party cookies, the request inside the iframe often does not carry the application's cookie, so logout silently does nothing. Do not rely on it in a new setup; prefer back-channel logout.
Other common mistakes
Requesting offline_access by default. A refresh token obtained with this scope keeps living after the provider session ends. The user believes they are logged out everywhere while tokens can still be minted in the background. Grant it only to clients that genuinely need offline access.
No absolute cap on refresh tokens. Rotation hands out a fresh token every time; without a maximum, a session that is used continuously lives forever. Define a total lifetime in addition to the idle timeout.
Not revoking tokens on password change. Users change their password because they suspect their account was taken. If refresh tokens are not revoked, the attacker stays in.
Sending the ID token to an API as if it were an access token. The audience (aud) of an ID token is the client itself, not the API. APIs should accept only access tokens issued for them.
When you do not need all this
If you have a single server-rendered application, no need for SSO and no other clients calling your API, using OIDC only at login and continuing with a classic server session is perfectly fine. You never store the tokens after login, so rotation and single-flight refresh do not apply. Even then, redirect to the provider on logout, or the "logout does not work" problem from the first section shows up exactly as described.
The short version: keep access tokens short, keep refresh tokens out of the browser and rotate them, collapse refreshes into a single flight, end the provider session on logout, and record the sid with your session so you can honour logouts that start somewhere else.
[OK] 30 records · 9 featured · 1 retainer · 20 standard
/02 services
services.tree
> note
· Prices are in USD. Volume discounts of 7% for 6-12 day projects and 14% for 13+ day projects apply. Programs of 100+ person-days are priced individually. Prices are negotiable based on scope, urgency and long-term collaboration.
> ls ~/products/ --open-source
[OK] 2 entries · 2 live
/03 products
products.list
liveopen source · mit/prod/01
filex
the self-hosted file manager that embeds anywhere
single go binary · web ui + desktop app · embeds as vue/react/web component · local, s3, sftp, webdav, ftp, smb · sso/ldap · rbac · multi-tenant · encrypted folders · mcp server for ai agents
We build infrastructure, automate everything, and keep systems running.
BRF Tech is a remote DevSecOps and software consulting firm based in Bursa, Türkiye. We operate across 30 service areas, from Kubernetes cluster management to serverless platform setup, CI/CD pipeline design to AI agent development.
What we do is simple: we set up your systems, automate them, and make sure they won't wake you up at 3 AM. We codify your infrastructure with Terraform, move your deployments to GitOps with ArgoCD, and monitor everything with Prometheus. When something is about to break, we step in before it does.
We're against vendor lock-in. We work with open-source tools, self-hosted solutions, and industry-standard technologies. We build your own serverless platform on Knative, isolate with Kata Containers, manage your secrets with Vault. Every project is delivered with clear scope, clear timeline, clear pricing.
DevSecOps & CI/CD
Kubernetes & Serverless
Infrastructure as Code
AI & Agent (MCP/ACP)
Security & Zero Trust
Full-Stack Development
Self-Hosted Solutions
> grep -i question ~/faq.md
[OK] 12 entries · click to expand
[?]What does BRF Tech do, and who do you work with?▾
BRF Tech is a remote DevSecOps and software consulting firm based in Bursa, Türkiye. We build infrastructure, automate it and keep it running. We work with startups getting their first product out the door, with companies that want to scale, migrate or harden the systems they already run, and with service providers operating their own cloud.
[?]Which areas do you cover?▾
We work across 30 service areas. The main ones are CI/CD and GitOps, Kubernetes and container infrastructure, infrastructure as code with Terraform, monitoring and SRE, private clouds on Cozystack, OpenStack and Virtuozzo along with migrations off VMware, security and zero trust architecture, database management, backup and disaster recovery, cloud migration and cost optimization, serverless platforms, AI integration and agent development, MVP and software development, self-hosted tooling, technical training and DevOps consulting. The Services section lists the scope and packages for each one.
[?]What are your software development services?▾
We offer MVP development, existing software performance optimization, backend API development (Node.js, Go, Python) and full-stack application development. Every project is delivered with minimal technical debt.
[?]Which DevOps tools do you work with?▾
From Kubernetes and Docker to Talos Linux, from Terraform and OpenTofu to Ansible, and across GitLab CI/CD, GitHub Actions, ArgoCD, Flux and Helm, we work with industry-standard tooling. For observability and error tracking we use Prometheus, Grafana, Loki, Tempo, OpenTelemetry and GlitchTip; for networking, Cilium and Envoy; for test automation, Playwright, Cypress, k6, Locust, Testcontainers and Trivy. We determine the most suitable toolset together, based on your project’s needs.
[?]How does a project get started?▾
Fill in the form in the Contact section, send us an email or give us a call. The first step is a free initial consultation where we listen to what you need, look at where things stand today and pin down the scope together. You then receive a proposal with a clear scope, timeline and price. Scope and payment terms are set for each project and agreed by both sides. If you need an NDA, we will sign one.
[?]How does pricing work?▾
Every project comes with a clear scope, timeline and price. Click any service in the Services section to see its packages with their scope, estimated duration and price, all in USD. Longer projects get a volume discount, and very large programs are priced individually. We give you the final price once the scope is settled in the initial consultation.
[?]Do you work remotely?▾
Yes, we are remote-first. We are based in Bursa, Türkiye, and work with clients around the world. Everything is set up in your own environment, whether that means your servers, your private cloud or a provider such as AWS, GCP, Azure or Hetzner.
[?]How do you handle the security of our systems and data?▾
We follow a DevSecOps approach, so security is built into the systems we set up from the start rather than added at the end. That includes secret management, role-based access control, zero trust networking and security scanning in the CI/CD pipeline. Because we favor open-source and self-hosted tools, your systems stay under your control instead of depending on a single vendor. We also run security audits and help you prepare for KVKK, GDPR, SOC 2 and ISO 27001 compliance. We sign an NDA when needed, and personal data is processed as described in our Privacy Policy, in line with KVKK, Turkey's data protection law.
[?]Do you offer support after delivery?▾
Yes, we can keep working together after handover. Our DevOps consulting runs two or three days a week or full time, and covers the technical roadmap, architecture reviews, team onboarding, code and infrastructure reviews and incident support. If you would rather have your own team run the system, we also offer technical training and mentoring programs.
[?]Do you have open-source products?▾
Yes. We turn the approaches we use in consulting into open-source products. filex is an MIT-licensed, self-hosted file manager. It runs as a single Go binary and can be embedded into other products as a Vue, React or web component. The source code is at github.com/BRF-Tech/filex, the project site is filex.sh, and a live demo runs at demo.filex.sh. RunR is an MIT-licensed, open-source serverless platform that runs on your own Kubernetes cluster. It runs functions, containers and WebAssembly on Knative and scales them to zero when they are idle. The source code is at github.com/BRF-Tech/runr, the project site is runr.sh, and a live demo runs at demo.runr.sh.
[?]Which languages do you work in?▾
We work in Turkish and English. Calls, emails and proposals are handled in whichever of the two you prefer.
[?]How can I get in touch?▾
Use the form in the Contact section, write to the email address listed there or call the phone number shown next to it. Our working hours are weekdays 09:00-18:00 (UTC+3), and we reply within 24 hours on average.
Automated build, test and deployment pipelines with GitHub Actions, GitLab CI/CD.
Automated build, test and deploy pipeline setup for existing or new repositories. GitHub Actions, GitLab CI/CD or preferred tool is used. Separate workflows are defined for staging + production environments.
Container architecture migration, cluster setup and orchestration.
Production-ready Kubernetes cluster setup on bare-metal or cloud. Includes Helm charts, Ingress, TLS certificate management, namespace isolation and RBAC.
Cozystack is an open-source cloud platform built on Kubernetes and the VMware alternative we recommend most. Virtual machines run on KubeVirt, while managed PostgreSQL, MySQL, Redis and Kafka services and dedicated tenant Kubernetes clusters are provisioned from the same dashboard and API. Includes installation on your own bare-metal servers on Talos Linux, replicated storage with LINSTOR/DRBD, network isolation with Kube-OVN, tenant and quota structure, monitoring, backup and a disaster recovery plan. After deployment we also handle upgrades, operations and support; since the platform is open source, there are no license fees and no vendor lock-in.
Packages
Virtual machine support on an existing Kubernetes cluster with KubeVirt
$2,800
4-6 person-days
Pilot setup (3 nodes, virtual machines + managed database)
$3,500
5-8 person-days
Production setup (HA + replicated storage + monitoring + backup)
$6,500
10-16 person-days
Multi-tenant private cloud (tenants, quotas, managed service catalog)
Planned, low-downtime migration of vSphere/ESXi environments to Cozystack, OpenStack or VHI.
A planned move to a VMware alternative for environments whose costs rose after Broadcom moved VMware licensing to subscription bundles, or whose renewal is coming up. We start with an inventory of your vSphere/ESXi estate (virtual machines, disks, networks, dependencies), then compare today's license cost with the total cost of the target platform. In most environments the target is Cozystack; OpenStack fits large-scale IaaS needs and Virtuozzo Hybrid Infrastructure fits storage-heavy service providers. A pilot runs on non-critical virtual machines, disks are converted with tools such as virt-v2v and Forklift, and the migration proceeds in waves within maintenance windows, with a rollback plan for every step.
Packages
Inventory + cost comparison + migration plan
$2,400
3-5 person-days
Pilot migration (up to 10 virtual machines)
$3,500
5-8 person-days
Phased migration (up to 100 virtual machines)
$9,750
15-22 person-days
Full data center migration (network + storage + backup)
OpenStack deployment, Neutron networking, Ceph/Cinder storage, upgrades and operations.
OpenStack deployment and operations in your own data center. A containerized, highly available control plane with Kolla-Ansible; Nova (compute), Keystone (identity), Glance (images) and Horizon (dashboard). On the network side, Neutron with OVN, VLAN/VXLAN, provider and tenant networks, floating IPs and the Octavia load balancer; on the storage side, Cinder block storage on Ceph RBD and optional S3-compatible object storage. For existing deployments: health checks, planned upgrades between releases, monitoring and alerting setup, and a backup strategy.
Packages
Health check + improvement report (existing deployment)
$2,400
3-5 person-days
Lab / PoC setup (single region, 3 nodes)
$3,500
5-8 person-days
Release upgrade (existing deployment)
$3,900
6-10 person-days
Production setup (HA control plane + Ceph + Neutron/OVN)
Hyperconverged infrastructure: multi-tenant cloud plus block and S3-compatible storage for service providers.
Hyperconverged infrastructure with Virtuozzo Hybrid Infrastructure, where compute, storage and networking run on the same servers. Block, S3-compatible object and NFS storage on software-defined storage, plus backup storage (Backup Gateway) for backup products such as Acronis. For service providers: a multi-tenant cloud with domains and projects, quotas, a self-service panel and an OpenStack-compatible API. Includes hardware sizing, network design, cluster deployment and expansion, version upgrades and operations support.
Packages
Pre-deployment assessment + hardware sizing
$2,400
3-4 person-days
Version upgrade / cluster expansion
$2,800
4-6 person-days
Hyperconverged cluster setup (storage + compute)
$3,900
6-10 person-days
Service provider setup (multi-tenant cloud + S3 + backup storage)
Migration of existing applications to container architecture.
Migration of existing applications to container architecture. Docker image design, Compose configuration and conversion to Kubernetes manifests. Kata Containers / gVisor can be included for advanced isolation.
Health check of your current environment, capacity planning, platform selection and a roadmap.
An independent assessment of your current virtualization environment (VMware vSphere, OpenStack, VHI or other KVM-based platforms). The health check covers cluster configuration, resource overcommit, storage latency, forgotten snapshots, backup and patch status. Capacity planning measures CPU, memory and storage growth to work out the hardware you will need next. Platform selection decides which workload should run where: Cozystack for teams running containers and virtual machines side by side, OpenStack for large-scale IaaS, VHI for storage-heavy service providers; staying on the current platform is also an option for some workloads. The deliverable is a written report with a cost comparison and a prioritized roadmap.
In-house tools like GitLab, Nextcloud, VPN, mail server.
Installation of tools like GitLab, Mattermost, Nextcloud, mail server, VPN, internal monitoring on company servers. Deployed on Docker Compose or Kubernetes.
DB + cache + code bottleneck identification and resolution.
Profiling of existing application, identification and resolution of bottlenecks. DB query optimization, caching layer (Redis), service-level improvements.
MCP/ACP agents, RAG pipelines, multi-agent orchestration, model serving.
LLM integration (OpenAI, Claude, Gemini, local models), tool-augmented AI agents with MCP (Model Context Protocol) and ACP (Agent Communication Protocol). RAG pipeline, multi-agent orchestration, model serving (vLLM/Ollama). AI layer for existing business processes.
Event-driven data pipeline with Apache Kafka, RabbitMQ, NATS. ETL/ELT orchestration with Apache Airflow, real-time data streaming, CDC (Change Data Capture). Data lake/warehouse design, schema registry, dead letter queue management.
Packages
Kafka/RabbitMQ setup + basic producer/consumer
$3,500
5-7 person-days
ETL pipeline (Airflow + source → warehouse)
$5,200
8-12 person-days
Full event-driven architecture (CDC + streaming + DLQ)
Hands-on technical training for your teams. Docker & container fundamentals, Kubernetes operations, Terraform IaC, CI/CD best practices, AI/LLM integration workshops. Practical exercises in live lab environments, content customized by skill level.
E2E test automation with Playwright, Cypress, load testing with k6/Gatling. Pre-deploy quality gate integrated into CI/CD pipeline, test coverage reporting, visual regression testing. Reduce test writing time by up to 60% with AI-assisted test generation.
Your Collected Personal Data, Collection Method and Legal Basis
Any information that identifies or makes you identifiable is considered "personal data." When you visit our website or use our services, contact information such as your name, surname, email address, phone number, as well as your IP address and browser cookie data may be collected through automatic or semi-automatic means. This data is processed based on the legal grounds specified in Article 5 of the Personal Data Protection Law No. 6698: "being directly related to the establishment or performance of a contract" and "being mandatory for the legitimate interests of the data controller, provided that it does not harm the fundamental rights and freedoms of the data subject."
Purpose of Processing Your Personal Data
Your collected personal data is processed for the purposes of providing and improving our services, fulfilling customer requests, meeting legal obligations, conducting information security processes and managing communication activities. Your data is processed in a limited and proportionate manner for the stated purposes; when the purpose ceases to exist, data is deleted, destroyed or anonymized.
To Whom and For What Purposes Collected Personal Data May Be Transferred
Your personal data may be transferred to public institutions and organizations as required by legal regulations, to our business partners and technical infrastructure providers for the purpose of delivering services, and to lawyers and consultants in legal disputes. Transfers are carried out in accordance with Articles 8 and 9 of the Law, with necessary technical and administrative measures in place.
Your Rights as a Data Subject
In accordance with Article 11 of Law No. 6698, you have the right to: learn whether your personal data is being processed; request information if it has been processed; learn the purpose of processing and whether it is used in accordance with its purpose; know the third parties to whom it is transferred domestically or abroad; request correction if it has been processed incompletely or incorrectly; request deletion or destruction within the framework of conditions set out in Article 7 of the Law; request that the operations carried out be notified to third parties to whom data has been transferred; object to any adverse result arising from the analysis of data exclusively through automated systems; and claim compensation for damages in case of unlawful processing. You may contact us through the communication channels on our website to exercise these rights.
Terms & Conditions
Terms & Conditions
1. Service Scope and Changes
BRF Tech conducts its software development, DevOps consulting, infrastructure setup and technical support services within the framework of these terms and conditions. The scope of service is determined separately for each project and finalized through mutual agreement. BRF Tech reserves the right to update the scope, pricing and technical details of its services, provided that prior notice is given.
2. Privacy Policy
Personal data collected within the scope of our services is processed in accordance with our Privacy Policy. For detailed information, please review our Privacy Policy page.
3. Service Usage and Responsibilities
Clients agree to use the provided services solely within legal and ethical boundaries. BRF Tech reserves the right to suspend or terminate services in the event of misuse, violation of third-party rights, or use for illegal activities. The client is responsible for the accuracy and currency of the information provided within the project scope.
4. Payment Terms
Payment terms are determined on a project basis and finalized through mutual agreement at the start of the project. Unless otherwise specified, invoices are payable within 15 days of project delivery. A monthly late payment interest of 2% may apply to overdue payments.
5. Cancellation and Refund Policy
Cancellation requests must be submitted in writing at least 7 days before the service start date. For projects already in progress, billing is based on the proportion of completed work. No refunds are issued for software and infrastructure components specifically developed within the project scope.