') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); fix(backend): return IdPOAuthAccessToken JWT timestamps in milliseconds by jacekradko · Pull Request #8771 · clerk/javascript · GitHub
Skip to content

fix(backend): return IdPOAuthAccessToken JWT timestamps in milliseconds - #8771

Merged
jacekradko merged 1 commit into
mainfrom
jacek/fix-idp-oauth-token-timestamps
Jun 9, 2026
Merged

fix(backend): return IdPOAuthAccessToken JWT timestamps in milliseconds#8771
jacekradko merged 1 commit into
mainfrom
jacek/fix-idp-oauth-token-timestamps

Conversation

@jacekradko

@jacekradkojacekradko commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

IdPOAuthAccessToken.fromJwtPayload set expiration, createdAt, and updatedAt from the JWT's raw second-based exp/iat, but M2MToken and the API response expose those fields in milliseconds. So the same OAuth token's timestamps came out 1000x off depending on whether you verified it as a JWT or fetched it from the API, and token.expiration < Date.now() was always true.

The fix is the * 1000 conversion that was already being done everywhere else:

payload.exp*1000// was: payload.exp

Token validity itself was never affected since the expired boolean already used * 1000, only the exposed timestamps were wrong. The OAuth-JWT verify test didn't assert these fields, which is why it slipped through, so I added that coverage.

Summary by CodeRabbit

  • Bug Fixes
    • OAuth access token verification now returns timestamp fields (expiration, createdAt, updatedAt) in milliseconds instead of seconds, ensuring consistency with other token types and API responses.

@changeset-bot

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ec97370

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
NameType
@clerk/backendPatch
@clerk/astroPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/honoPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercelBot commented Jun 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 7, 2026 11:59pm

Request Review

@coderabbitai

coderabbitaiBot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR fixes timestamp field values in IdPOAuthAccessToken when verifying OAuth access tokens as JWTs. The expiration, createdAt, and updatedAt fields are now populated in milliseconds by converting JWT exp/iat claim values (which are in seconds) via multiplication by 1000, aligning with M2MToken behavior and API responses.

Changes

OAuth Token Millisecond Timestamps

Layer / File(s)Summary
Millisecond timestamp conversion in OAuth token factory
packages/backend/src/api/resources/IdPOAuthAccessToken.ts
IdPOAuthAccessToken.fromJwtPayload multiplies JWT exp and iat claim values by 1000 when setting expiration, createdAt, and updatedAt.
Test assertions and release documentation
packages/backend/src/tokens/__tests__/verify.test.ts, .changeset/idp-oauth-token-ms-timestamps.md
OAuth JWT verification test assertions verify millisecond timestamps, and a patch changeset documents the timestamp field consistency fix.

🎯 2 (Simple) | ⏱️ ~8 minutes

A rabbit hops through timestamps with glee,
Seconds now dance to millisecond decree,
OAuth tokens sing in sync, unified time,
API and backend aligned in their rhyme. 🐰⏰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Title check✅ PassedThe title directly and concisely describes the main fix: converting IdPOAuthAccessToken JWT timestamps from seconds to milliseconds, which is the core purpose of this changeset.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-newBot commented Jun 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8771

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8771

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8771

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8771

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8771

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8771

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8771

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8771

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8771

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8771

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8771

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8771

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8771

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8771

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8771

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8771

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8771

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8771

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8771

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8771

commit: ec97370

@github-actions

Copy link
Copy Markdown
Contributor

API Changes Report

Generated by Break Check on 2026-06-08T00:02:43.956Z

Summary

MetricCount
Packages analyzed19
Packages with changes1
🔴 Breaking changes0
🟡 Non-breaking changes1
🟢 Additions0

🤖 This report was reviewed by claude-sonnet-4-6.

Note
Break Check could not snapshot 3 subpaths; the diff below excludes them.

  • @clerk/astro ./env: Internal Error: Unable to determine module for: /home/runner/_work/javascript/javascript/packages/astro/env.d.ts You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
  • @clerk/shared ./cookie: Internal Error: Unable to follow symbol for "Cookies" You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
  • @clerk/testing ./cypress: Symbol not found for identifier: Cypress

@clerk/shared

Current version: 4.15.0
Recommended bump: MINOR → 4.16.0

Subpath ./apiUrlFromPublishableKey

🟡 Non-breaking Changes (1)

Modified: apiUrlFromPublishableKey
- apiUrlFromPublishableKey: (publishableKey: string) => "https://api.clerk.com" | "https://api.lclclerk.com" | "https://api.clerkstage.dev"+ apiUrlFromPublishableKey: (publishableKey: string) => "https://api.lclclerk.com" | "https://api.clerkstage.dev" | "https://api.clerk.com"

Static analyzer: Breaking change in function apiUrlFromPublishableKey: Return type changed: "https://api.clerk.com"|"https://api.lclclerk.com"|"https://api.clerkstage.dev""https://api.lclclerk.com"|"https://api.clerkstage.dev"|"https://api.clerk.com"

🤖 AI review (reclassified as non-breaking) (98%): The return type is a union of the exact same three string literals; only the order of union members changed, which is structurally identical in TypeScript — no well-typed consumer code is affected.


Report generated by Break Check

Last ran on ec97370. Pushes that change no tracked declarations (no API surface change vs. base) are skipped and don't update this comment.

@wobsorianowobsoriano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catching!

@jacekradko
jacekradko merged commit 48b187d into mainJun 9, 2026
50 checks passed
@jacekradko
jacekradko deleted the jacek/fix-idp-oauth-token-timestamps branch June 9, 2026 14:31
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@jacekradko@wobsoriano