Skip to content

Fix/usertokenclient refreshtoken#463

Merged
rido-min merged 6 commits intomainfrom
fix/usertokenclient-refreshtoken
Jul 17, 2025
Merged

Fix/usertokenclient refreshtoken#463
rido-min merged 6 commits intomainfrom
fix/usertokenclient-refreshtoken

Conversation

@rido-min
Copy link
Copy Markdown
Member

@rido-min rido-min commented Jul 16, 2025

fixes #459 and #263

This pull request introduces significant changes to the agents-hosting package, focusing on enhancing token management, improving the CloudAdapter and OAuthFlow classes, and simplifying error handling within the UserTokenClient. The most important updates involve replacing the BaseAdapter with CloudAdapter, improving token refresh logic, and streamlining error handling in the UserTokenClient.

Token Management Enhancements:

  • packages/agents-hosting/src/oauth/oAuthFlow.ts: Replaced the initializeTokenClient method with refreshToken, adding token caching and automatic refresh logic using jwt. This ensures that tokens are kept up-to-date and reduces redundant initialization. [1] [2]

Adapter Improvements:

Error Handling Simplification:

Authorization Enhancements:

Miscellaneous Updates:

Copilot AI review requested due to automatic review settings July 16, 2025 23:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances token management by introducing automatic refresh and caching in OAuthFlow, streamlines UserTokenClient with Axios interceptors and error handling, and replaces the legacy BaseAdapter with a more flexible CloudAdapter across samples, tests, and application setup.

  • Add refreshToken in OAuthFlow using JWT for caching and auto-refresh.
  • Refactor UserTokenClient to remove redundant try-catches, add response interceptors, and updateAuthToken.
  • Update adapter logic to use CloudAdapter with optional AuthConfiguration, AuthProvider, and UserTokenClient.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
samples/compat/oauthFlowHandler.ts Updated sample to load auth config and instantiate OAuthFlow with new UserTokenClient.
samples/auth/autoAuth.ts Removed trailing whitespace.
packages/agents-hosting/test/hosting/oauthflow.test.ts Updated tests to mock MsalTokenProvider, integrate refreshToken calls, and adjust context stubbing.
packages/agents-hosting/src/oauth/userTokenClient.ts Refactored constructor signature, removed redundant error handling, added Axios response interceptors, and updateAuthToken.
packages/agents-hosting/src/oauth/oAuthFlow.ts Replaced initializeTokenClient with refreshToken, introduced JWT caching and constructor signature update.
packages/agents-hosting/src/oauth/index.ts Removed duplicate export of userTokenClient.
packages/agents-hosting/src/cloudAdapter.ts Modified constructor to load default config and accept optional UserTokenClient; ensure adapter fallback.
packages/agents-hosting/src/baseAdapter.ts Added userTokenClient property on BaseAdapter.
packages/agents-hosting/src/app/authorization.ts Updated Authorization to accept and pass through UserTokenClient to OAuthFlow.
packages/agents-hosting/src/app/agentApplication.ts Swapped BaseAdapter for CloudAdapter, added fallback instantiation, and wired token client into auth.
packages/agents-hosting-express/src/startServer.ts Changed CloudAdapter initialization to no-arg constructor for default environment config.
__state/state.json Added an initial empty state file.
Comments suppressed due to low confidence (1)

packages/agents-hosting/src/cloudAdapter.ts:51

  • MsalTokenProvider is referenced but not imported. Add import { MsalTokenProvider } from './auth/authProvider' (or the correct path) to avoid runtime errors.
    this.authProvider = authProvider ?? new MsalTokenProvider()

Comment thread samples/compat/oauthFlowHandler.ts Outdated
Comment thread packages/agents-hosting/src/oauth/oAuthFlow.ts Outdated
Comment thread packages/agents-hosting/src/oauth/oAuthFlow.ts Outdated
Comment thread packages/agents-hosting/src/oauth/index.ts Outdated
Comment thread packages/agents-hosting-express/src/startServer.ts
Comment thread packages/agents-hosting/src/oauth/userTokenClient.ts
@rido-min rido-min enabled auto-merge (squash) July 17, 2025 00:44
@rido-min rido-min merged commit be16ea7 into main Jul 17, 2025
7 checks passed
@rido-min rido-min deleted the fix/usertokenclient-refreshtoken branch July 17, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UserTokenService does not refresh tokens

3 participants