Skip to content

Conversation

@ruchI9897
Copy link
Contributor

No description provided.

@ruchI9897 ruchI9897 requested a review from a team as a code owner December 16, 2025 13:41
@mnk-blr
Copy link
Collaborator

mnk-blr commented Dec 16, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ruchI9897, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the authentication system by introducing a proactive token refresh mechanism. It adds a new event to notify when an authentication token is about to expire and implements logic to automatically acquire a fresh token, particularly for cookieless trusted authentication scenarios. This change aims to improve the user experience by preventing session interruptions due to expired tokens.

Highlights

  • New Token Expiration Event: Introduced a new EmbedEvent.TokenExpiringSoon to signal when an authentication token is nearing its expiration, enabling proactive handling.
  • Automatic Token Refresh Logic: Implemented a new handler tokenExpiringSoon that automatically attempts to fetch a new authentication token when the TokenExpiringSoon event is triggered, primarily for TrustedAuthTokenCookieless authentication types.
  • Authentication Token Validation Bypass: Modified the getAuthenticationToken function to accept an optional skipvalidation parameter, allowing the token refresh mechanism to bypass cached token validation when acquiring a new token.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 16, 2025

Open in StackBlitz

npm i https://pkg.pr.new/thoughtspot/visual-embed-sdk/@thoughtspot/visual-embed-sdk@388

commit: 4daa1d8

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism for proactively refreshing authentication tokens by adding a TokenExpiringSoon event and its handler. The getAuthenticationToken function is also updated to support skipping cache validation. My review identified a critical logical bug in the new tokenExpiringSoon handler that would cause it to incorrectly signal an authentication failure even on success. I've also pointed out an un-awaited asynchronous call and a naming convention issue, providing suggestions to address them.

Comment on lines 562 to 583
private tokenExpiringSoon = async (_: any, responder: any) => {
const { authType } = this.embedConfig;
let { autoLogin } = this.embedConfig;
// Default autoLogin: true for cookieless if undefined/null, otherwise
// false
autoLogin = autoLogin ?? (authType === AuthType.TrustedAuthTokenCookieless);
if (autoLogin && authType === AuthType.TrustedAuthTokenCookieless) {
try {
const authToken = await getAuthenticationToken(this.embedConfig, true);
responder({
type: EmbedEvent.AuthExpire,
data: { authToken },
});
} catch (e) {
logger.error(`${ERROR_MESSAGE.INVALID_TOKEN_ERROR} Error : ${e?.message}`);
processAuthFailure(e, this.isPreRendered ? this.preRenderWrapper : this.el);
}
} else if (autoLogin) {
handleAuth();
}
notifyAuthFailure(AuthFailureType.EXPIRY);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The new tokenExpiringSoon method has a few issues:

  1. Unconditional Failure Notification (Critical): It unconditionally calls notifyAuthFailure(AuthFailureType.EXPIRY) at the end. This is incorrect as it signals an authentication failure even when the token refresh is successful. This call should only happen if autoLogin is disabled or if the refresh fails.

  2. Un-awaited Asynchronous Call (High): The call to handleAuth() is not awaited. Since handleAuth is an async function, this will lead to a race condition where notifyAuthFailure is called before authentication completes.

  3. Code Duplication (Medium): This method is almost identical to the existing updateAuthToken method. This duplication should be avoided by refactoring the common logic into a shared private method.

Here is a suggested fix that addresses the critical and high severity issues:

    private tokenExpiringSoon = async (_: any, responder: any) => {
        const { authType } = this.embedConfig;
        let { autoLogin } = this.embedConfig;
        // Default autoLogin: true for cookieless if undefined/null, otherwise
        // false
        autoLogin = autoLogin ?? (authType === AuthType.TrustedAuthTokenCookieless);
        if (autoLogin) {
            if (authType === AuthType.TrustedAuthTokenCookieless) {
                try {
                    const authToken = await getAuthenticationToken(this.embedConfig, true);
                    responder({
                        type: EmbedEvent.AuthExpire,
                        data: { authToken },
                    });
                } catch (e) {
                    logger.error(`${ERROR_MESSAGE.INVALID_TOKEN_ERROR} Error : ${e?.message}`);
                    processAuthFailure(e, this.isPreRendered ? this.preRenderWrapper : this.el);
                }
            } else {
                await handleAuth();
            }
        } else {
            notifyAuthFailure(AuthFailureType.EXPIRY);
        }
    }

Comment on lines +19 to +23
export async function getAuthenticationToken(embedConfig: EmbedConfig, skipvalidation: boolean = false): Promise<string> {
const cachedAuthToken = getCacheAuthToken();
// Since we don't have token validation enabled , we cannot tell if the
// cached token is valid or not. So we will always fetch a new token.
if (cachedAuthToken && !embedConfig.disableTokenVerification) {
if (cachedAuthToken && !embedConfig.disableTokenVerification && !skipvalidation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The parameter name skipvalidation does not follow the camelCase naming convention used throughout the codebase (e.g., disableTokenVerification, cachedAuthToken). For consistency and better readability, it should be renamed to skipValidation.

Suggested change
export async function getAuthenticationToken(embedConfig: EmbedConfig, skipvalidation: boolean = false): Promise<string> {
const cachedAuthToken = getCacheAuthToken();
// Since we don't have token validation enabled , we cannot tell if the
// cached token is valid or not. So we will always fetch a new token.
if (cachedAuthToken && !embedConfig.disableTokenVerification) {
if (cachedAuthToken && !embedConfig.disableTokenVerification && !skipvalidation) {
export async function getAuthenticationToken(embedConfig: EmbedConfig, skipValidation: boolean = false): Promise<string> {
const cachedAuthToken = getCacheAuthToken();
// Since we don't have token validation enabled , we cannot tell if the
// cached token is valid or not. So we will always fetch a new token.
if (cachedAuthToken && !embedConfig.disableTokenVerification && !skipValidation) {

@sonar-prod-ts
Copy link

sonar-prod-ts bot commented Dec 17, 2025

SonarQube Quality Gate

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

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.

3 participants