Repository: hashicorp/vault
File: ui/app/components/auth/form/saml.ts (TypeScript)

Code before:
        'vaultSAMLWindow',
        `width=${POPUP_WIDTH},height=${POPUP_HEIGHT},resizable,scrollbars=yes,top=${top},left=${left}`
      );

      await this.exchangeSAMLTokenPollID.perform(samlWindow, { path });
    }
  }

  exchangeSAMLTokenPollID = task(async (samlWindow, { path }) => {
    // start watching the popup window and the current one
    this.watchPopup.perform(samlWindow);
    this.watchCurrent.perform(samlWindow);

    // TODO CMB - when wiring up components check if this is still necessary
    // pass namespace from state back to AuthForm
    // this.args.onNamespace(namespace);
    let resp;
    try {
      resp = await this.pollForToken(samlWindow, { path });
      this.closeWindow(samlWindow);
    } catch (error) {
      this.cancelLogin(samlWindow, errorMessage(error));
      return;
    }

    // We've go a response from the polling request
    // pass MFA data or use the Vault token (client_token) to continue the auth
    const mfa_requirement = resp?.mfa_requirement;
    const client_token = resp?.client_token;
    if (mfa_requirement) {
      this.handleMfa(mfa_requirement, path);
      return;
    }
    if (client_token) {
      this.continueLogin({ token: client_token });
      return;
    }

    // If there's a problem with the SAML exchange the auth workflow should fail earlier.
    // Including this catch just in case, though it's unlikely this will be hit.
    this.handleSAMLError('Missing token. Please try again.');
    return;
  });

  async pollForToken(samlWindow: Window, { path = '' }) {
    // Poll every one second for the token to become available
    const WAIT_TIME = Ember.testing ? 50 : 1000;
    const MAX_TIME = 180; // 3 minutes in seconds

    const adapter = this.store.adapterFor('auth-method') as AuthMethodAdapter;
    // Wait up to 3 minutes for a token to become available

Review comment (suggestion):
nit: small typo
```suggestion
    // We've got a response from the polling request
```

Code after:
        'vaultSAMLWindow',
        `width=${POPUP_WIDTH},height=${POPUP_HEIGHT},resizable,scrollbars=yes,top=${top},left=${left}`
      );

      await this.exchangeSAMLTokenPollID.perform(samlWindow, { path });
    }
  }

  exchangeSAMLTokenPollID = task(async (samlWindow, { path }) => {
    // start watching the popup window and the current one
    this.watchPopup.perform(samlWindow);
    this.watchCurrent.perform(samlWindow);

    // TODO CMB - when wiring up components check if this is still necessary
    // pass namespace from state back to AuthForm
    // this.args.onNamespace(namespace);
    let resp;
    try {
      resp = await this.pollForToken(samlWindow, { path });
      this.closeWindow(samlWindow);
    } catch (error) {
      this.cancelLogin(samlWindow, errorMessage(error));
      return;
    }

    // We've got a response from the polling request
    // pass MFA data or use the Vault token (client_token) to continue the auth
    const mfa_requirement = resp?.mfa_requirement;
    const client_token = resp?.client_token;
    if (mfa_requirement) {
      this.handleMfa(mfa_requirement, path);
      return;
    }
    if (client_token) {
      this.continueLogin({ token: client_token });
      return;
    }

    // If there's a problem with the SAML exchange the auth workflow should fail earlier.
    // Including this catch just in case, though it's unlikely this will be hit.
    this.handleSAMLError('Missing token. Please try again.');
    return;
  });

  async pollForToken(samlWindow: Window, { path = '' }) {
    // Poll every one second for the token to become available
    const WAIT_TIME = Ember.testing ? 50 : 1000;
    const MAX_TIME = 180; // 3 minutes in seconds

    const adapter = this.store.adapterFor('auth-method') as AuthMethodAdapter;
    // Wait up to 3 minutes for a token to become available