Skip to content

Enhances authentication token handling with metadata#4896

Open
sergeibbb wants to merge 3 commits intomainfrom
4880-token-type-to-errors
Open

Enhances authentication token handling with metadata#4896
sergeibbb wants to merge 3 commits intomainfrom
4880-token-type-to-errors

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

Notes about the PR size

Despite it looks big, the only thing is done is passing more information from the point where we have the whole session to the point where a error is handled and the AuthenticationError is formed. Nothing else is changed. The PR does not change the behavior. For example,

  • I have not added or removed any try-catch blocks
  • I haven't added new handling wrappers in a method even when a neighboring method, that looks similar, has such wrappers
    • for such changes I would need to identify whether a wrapper missed by a mistake or by a reason, identify a problem that it can cause, and make sure that a change does not produce new problems. That's why in this ticket I'm keeping things unchanged as much as possible.

Notes about the solution

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
5 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 threads richer authentication-token metadata through integrations to improve diagnostics (especially for auth failures) without intending to change request behavior.

Changes:

  • Adds TokenInfo / TokenWithInfo (including an obfuscated microHash) plus helpers (toTokenInfo, toTokenWithInfo).
  • Extends ProviderAuthenticationSession and stored sessions to carry auth type (oauth/pat), cloud flag, scopes, and expiration.
  • Updates AuthenticationError to accept TokenInfo and append token metadata in toString() for improved logging.
  • Refactors provider integrations/APIs (GitHub, GitLab, Bitbucket, Azure DevOps, Jira, Linear) to pass TokenWithInfo through request layers and use it when constructing auth/rate-limit errors.
  • Updates ProvidersApi to accept TokenOptInfo and to derive token+metadata from the authentication service when needed.
  • Enhances GitKraken server connection error handling to include token metadata when throwing auth-related errors.

Technical Notes: Token metadata is intended to be surfaced primarily in logs via Error.toString() to help correlate auth/session issues across refresh and provider boundaries.

🤖 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.

@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
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 added a commit that referenced this pull request Jan 19, 2026
@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.

sergeibbb added a commit that referenced this pull request Jan 20, 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 20, 2026
sergeibbb added a commit that referenced this pull request Jan 20, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from b08cdc0 to 56c0f92 Compare January 20, 2026 13:55
sergeibbb added a commit that referenced this pull request Jan 20, 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 20, 2026
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 56c0f92 to 9d89e29 Compare January 20, 2026 14:19
sergeibbb added a commit that referenced this pull request Jan 20, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
@sergeibbb sergeibbb marked this pull request as draft January 20, 2026 19:05
sergeibbb added a commit that referenced this pull request Jan 20, 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 6984d8a to 08e3d42 Compare January 22, 2026 17:56
sergeibbb added a commit that referenced this pull request Jan 22, 2026
sergeibbb added a commit that referenced this pull request Jan 22, 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 22, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
sergeibbb added a commit that referenced this pull request Jan 22, 2026
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 08e3d42 to 30d9c9f Compare January 22, 2026 18:00
sergeibbb added a commit that referenced this pull request Jan 22, 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 22, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
sergeibbb added a commit that referenced this pull request Jan 22, 2026
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 30d9c9f to 4db1dd5 Compare January 22, 2026 18:20
sergeibbb added a commit that referenced this pull request Jan 23, 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 23, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
sergeibbb added a commit that referenced this pull request Jan 23, 2026
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 4db1dd5 to bd4f62d Compare January 23, 2026 13:32
sergeibbb added a commit that referenced this pull request Jan 23, 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 23, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
sergeibbb added a commit that referenced this pull request Jan 23, 2026
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from bd4f62d to 83ffec2 Compare January 23, 2026 16:17
sergeibbb added a commit that referenced this pull request Jan 26, 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 26, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
sergeibbb added a commit that referenced this pull request Jan 26, 2026
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 83ffec2 to 676b692 Compare January 26, 2026 10:43
sergeibbb added a commit that referenced this pull request Jan 26, 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 26, 2026
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 676b692 to 649cd07 Compare January 26, 2026 10:58
sergeibbb added a commit that referenced this pull request Jan 26, 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)
Introduces a `type` property to authentication session and token information objects.

*   Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token.
*   Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider.
*   Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting.

(#4880, #4896)
@sergeibbb sergeibbb force-pushed the 4880-token-type-to-errors branch from 649cd07 to 46a8de0 Compare January 27, 2026 12:12
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

1 participant