Skip to content

Add SignalR TypeScript auth refresh - #67964

Merged
BrennanConroy merged 7 commits into
mainfrom
brennanconroy-ts-auth-refresh
Jul 30, 2026
Merged

BrennanConroy merged 7 commits into
mainfrom
brennanconroy-ts-auth-refresh

Conversation

@BrennanConroy

Copy link
Copy Markdown
Member

Summary

  • Add opt-in TypeScript client auth-refresh APIs and exported option/context types.
  • Parse negotiated/refreshed token lifetimes, call POST /refresh?id={connectionToken}, schedule automatic refresh, and expose manual refresh from HubConnection.
  • Preserve redirect/Azure SignalR behavior by refreshing against the original app endpoint while keeping/adopting transport tokens correctly.
  • Add focused unit coverage and a browser functional test that refreshes non-identity claims without changing the user identifier.

Validation

  • npm run build in src\SignalR\clients\ts\signalr
  • Focused Jest for HttpConnection.test.ts and HubConnection.test.ts
  • HttpConnection and HubConnection open-handle checks
  • Functional TS tsconfig.json --noEmit
  • Targeted C# functional app build
  • Browser functional tests: TOTAL: 266 SUCCESS
  • git diff --check

@gfoidl gfoidl added area-signalr Includes: SignalR clients and servers feature-client-javascript Related to the SignalR JS client labels Jul 23, 2026
@gfoidl
gfoidl temporarily deployed to copilot-pat-pool July 23, 2026 12:21 — with GitHub Actions Inactive
@gfoidl
gfoidl temporarily deployed to copilot-pat-pool July 23, 2026 12:21 — with GitHub Actions Inactive
@BrennanConroy
BrennanConroy marked this pull request as ready for review July 24, 2026 19:51
@BrennanConroy
BrennanConroy requested a review from halter73 as a code owner July 24, 2026 19:51
Copilot AI review requested due to automatic review settings July 24, 2026 19:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in authentication refresh feature to the SignalR TypeScript client, enabling both manual and scheduled token refresh based on server-reported lifetimes, while preserving redirect/Azure SignalR token semantics.

Changes:

  • Introduces withAuthenticationRefresh(...) on HubConnectionBuilder, new exported option/context types, and a HubConnection.refreshAuthentication() API with optional auto-refresh scheduling.
  • Extends HttpConnection + AccessTokenHttpClient to capture token lifetimes from negotiate/refresh responses and to refresh via POST /refresh?id=... while keeping transport vs app tokens separated correctly.
  • Adds/updates Jest unit tests and a browser functional test validating refreshed claims without changing the user identifier.
Show a summary per file
File Description
src/SignalR/clients/ts/signalr/tests/OutputSize.test.ts Updates size threshold for the minified bundle to account for added client functionality.
src/SignalR/clients/ts/signalr/tests/HubConnection.test.ts Adds unit coverage for manual refresh, auto-refresh scheduling, cleanup, and failure logging.
src/SignalR/clients/ts/signalr/tests/HttpConnection.test.ts Adds unit coverage for negotiate/refresh token lifetime parsing and refresh token behavior (redirect + token handling).
src/SignalR/clients/ts/signalr/src/index.ts Exports new authentication refresh option/context types as part of the public TS surface.
src/SignalR/clients/ts/signalr/src/IAuthenticationRefreshOptions.ts Adds the new public option + callback context type definitions.
src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts Adds withAuthenticationRefresh(...) to opt into refresh behavior.
src/SignalR/clients/ts/signalr/src/HubConnection.ts Implements manual refresh API + auto-refresh timer scheduling and callback invocation.
src/SignalR/clients/ts/signalr/src/HttpConnection.ts Implements /refresh request flow, token lifetime parsing, and feature wiring to HubConnection.
src/SignalR/clients/ts/signalr/src/AccessTokenHttpClient.ts Adds refresh-specific token factory behavior and tracks refresh request tokens.
src/SignalR/clients/ts/FunctionalTests/ts/HubConnectionTests.ts Adds browser functional test validating refreshed claims with stable user identifier.
src/SignalR/clients/ts/FunctionalTests/Startup.cs Enables authentication refresh on the authorized hub and issues scoped JWTs for test validation.
src/SignalR/clients/ts/FunctionalTests/AuthorizedHub.cs Adds hub methods to read name identifier + claim values for refresh validation.

Copilot's findings

Comments suppressed due to low confidence (1)

src/SignalR/clients/ts/signalr/src/HubConnection.ts:1135

  • This log message interpolates the raw caught value, which can produce unhelpful output like '[object Object]'. Use getErrorString(e) for consistent, readable error logging (as done elsewhere in this file).
            this._logger.log(LogLevel.Error, `An onAuthenticationRefreshFailed callback threw error '${e}'.`);
  • Files reviewed: 12/12 changed files
  • Comments generated: 3

@ellisonantoniafelicia-star

Copy link
Copy Markdown

Pay Github Sponsors program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-signalr Includes: SignalR clients and servers feature-client-javascript Related to the SignalR JS client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants