Skip to content

Conversation

@sergeibbb
Copy link
Member

@sergeibbb sergeibbb commented Jan 19, 2026

Description

Implements #4880

Introduces TokenInfo and TokenWithInfo types to encapsulate authentication access tokens along with their relevant metadata, such as provider ID, cloud status, scopes, and expiration.

This refactoring replaces direct accessToken strings with the new TokenWithInfo object across various API calls within integration providers. Benefits include:

  • Provides richer context in AuthenticationError messages for improved debugging.
  • Increases type safety and clarity by explicitly passing token metadata.

Implementation Details

There was an option to catch AuthenticationError upper in the call-stack and enrich it with the session metadata. By doing this I could reduce amount of changes. But it's hard identify all the possible points where it should be done, because a thrown exception does not highlight its type: such a place where AuthenticationError caught and logged can be missed, it can be caught earlier before it reaches your point, new points can appear later.

By requiring AuthenticationError to receive all the meta information everything is checked at compile time. Yes, we have to do massive changes once, but then it's always correct and checked by the compiler.

Checklist

  • I have followed the guidelines in the Contributing document
  • My changes follow the coding style of this project
  • My changes build without any errors or warnings
  • My changes have been formatted and linted
  • My changes include any required corresponding changes to the documentation (including CHANGELOG.md and README.md)
  • My changes have been rebased and squashed to the minimal number (typically 1) of relevant commits
  • My changes have a descriptive commit message with a short title, including a Fixes $XXX - or Closes #XXX - prefix to auto-close the issue that your PR addresses

@sergeibbb sergeibbb linked an issue Jan 19, 2026 that may be closed by this pull request
2 tasks
@sergeibbb sergeibbb added this to the 17.10 milestone Jan 19, 2026
@sergeibbb sergeibbb marked this pull request as ready for review January 19, 2026 14:10
sergeibbb added a commit that referenced this pull request Jan 19, 2026
Introduces `TokenInfo` and `TokenWithInfo` types to encapsulate
authentication access tokens along with their relevant metadata, such as
provider ID, cloud status, scopes, and expiration.

This refactoring replaces direct `accessToken` strings with the new
`TokenWithInfo` object across various API calls within integration
providers. Benefits include:
- Provides richer context in `AuthenticationError` messages for improved
debugging.
- Increases type safety and clarity by explicitly passing token
metadata.
(#4880, #4896)
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from c12af76 to 65aeae8 Compare January 19, 2026 14:12
sergeibbb added a commit that referenced this pull request Jan 19, 2026
@augmentcode
Copy link

augmentcode bot commented Jan 19, 2026

🤖 Augment PR Summary

Summary: This PR refactors integration authentication to carry structured token metadata alongside access tokens, improving diagnostics and type-safety.

Changes:

  • Introduces TokenInfo/TokenWithInfo and helpers (toTokenInfo, toTokenWithInfo) to bundle provider id, cloud/self-managed flag, scopes, expiry, and a short token “micro-hash”
  • Updates AuthenticationError to include token metadata in error messages to aid debugging and support investigations (4879: Provide the Authentication error with token type and scopes #4880)
  • Refactors Providers API to accept token+metadata objects instead of raw token strings, and to normalize auth/rate-limit errors using the richer context
  • Propagates the new token wrapper through GitHub/GitLab/Azure DevOps/Bitbucket/Jira/Linear integrations and related sub-providers
  • Updates GitKraken server request error handling to emit AuthenticationError with token metadata
  • Adds a CHANGELOG entry noting the enhanced authentication error details

Technical Notes: Token metadata includes a short MD5-based micro-hash intended for log correlation without exposing the full token.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

src/errors.ts Outdated
const typeStrPiece = type ? ` ${type}` : '';
const expiresAtPiece = expiresAt ? `expires at ${expiresAt.toISOString()}` : '';
const scopesStrPiece = scopes ? `[${scopes.join(',')}]` : '';
const authInfo = `(token info: ${[cloudStrPiece, typeStrPiece, expiresAtPiece, scopesStrPiece].join(', ')})`;
Copy link

Choose a reason for hiding this comment

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

In AuthenticationError, authInfo joins a fixed array that can include empty strings (e.g., missing type/expiresAt), which can yield confusing output like cloud, , , [] and reduces the value of the added diagnostics. Consider omitting empty segments (and avoiding the leading space in typeStrPiece) so the metadata is consistently readable.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

);
const token = tokenWithInfo.accessToken;

return (
Copy link

Choose a reason for hiding this comment

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

Unlike getCurrentUser/getCurrentUserForResource, getCurrentUserForInstance doesn’t wrap provider exceptions via handleProviderError, so 401/403s may bypass the new AuthenticationError(TokenInfo, ...) path and lose the extra metadata. Consider handling errors consistently here so callers get normalized auth/rate-limit errors.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

@sergeibbb sergeibbb marked this pull request as draft January 19, 2026 17:58
sergeibbb added a commit that referenced this pull request Jan 19, 2026
Introduces `TokenInfo` and `TokenWithInfo` types to encapsulate
authentication access tokens along with their relevant metadata, such as
provider ID, cloud status, scopes, and expiration.

This refactoring replaces direct `accessToken` strings with the new
`TokenWithInfo` object across various API calls within integration
providers. Benefits include:
- Provides richer context in `AuthenticationError` messages for improved
debugging.
- Increases type safety and clarity by explicitly passing token
metadata.
(#4880, #4896)
sergeibbb added a commit that referenced this pull request Jan 19, 2026
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 65aeae8 to 983fab9 Compare January 19, 2026 18:42
sergeibbb added a commit that referenced this pull request Jan 19, 2026
Introduces `TokenInfo` and `TokenWithInfo` types to encapsulate
authentication access tokens along with their relevant metadata, such as
provider ID, cloud status, scopes, and expiration.

This refactoring replaces direct `accessToken` strings with the new
`TokenWithInfo` object across various API calls within integration
providers. Benefits include:
- Provides richer context in `AuthenticationError` messages for improved
debugging.
- Increases type safety and clarity by explicitly passing token
metadata.
(#4880, #4896)
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 983fab9 to 8646077 Compare January 19, 2026 18:44
sergeibbb added a commit that referenced this pull request Jan 19, 2026
Introduces `TokenInfo` and `TokenWithInfo` types to encapsulate
authentication access tokens along with their relevant metadata, such as
provider ID, cloud status, scopes, and expiration.

This refactoring replaces direct `accessToken` strings with the new
`TokenWithInfo` object across various API calls within integration
providers. Benefits include:
- Provides richer context in `AuthenticationError` messages for improved
debugging.
- Increases type safety and clarity by explicitly passing token
metadata.
(#4880, #4896)
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 8646077 to b08cdc0 Compare January 19, 2026 18:45
@sergeibbb sergeibbb marked this pull request as ready for review January 19, 2026 18:48
Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

export function toTokenInfo<T extends IntegrationIds | 'gitkraken'>(
providerId: T,
accessToken: string | undefined,
info: { cloud: boolean; scopes?: readonly string[]; expiresAt?: Date },
Copy link

Choose a reason for hiding this comment

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

TokenInfo includes type, but toTokenInfo (and ProviderAuthenticationSession) never populates it, so AuthenticationError “token details” will always omit the auth type.
Consider plumbing CloudIntegrationAuthenticationSession.type through to ProviderAuthenticationSession and including it in toTokenInfo so the new diagnostics are consistent.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

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.

4879: Provide the Authentication error with token type and scopes

2 participants