Why am I Receiving a "This Session Has Expired" Message When Trying to Connect to Pipedream Connect?

This topic was automatically generated from Slack. You can find the original thread here.

Pipedream Connect – I am getting “This session has expired.” message when trying to connect account. It was working a few weeks ago.

Frontend (React, TS)

const generatePipedreamToken: any = async () => {
    const { token } = await createPipedreamToken(user!.workspaceId);
    return token;
  };

  const pd = createFrontendClient({
    environment: 'production',
    externalUserId: user!.workspaceId,
  });

  async function connectPipedreamAccount(app: string, oauthAppId: string) {
    console.log('Connecting account...');
    const token = await generatePipedreamToken();
    pd.connectAccount({
      app, // Pass the app name slug of the app you want to integrate
      token, // The token you received from your server above
      oauthAppId,
      onSuccess: ({ id: accountId }: any) => {
        console.log(`Account successfully connected: ${accountId}`);
      },
    });

Backend (NodeJS, TS)

constructor() {
  this.pd = createBackendClient({
      projectId: PIPEDREAM_PROJECT_ID!,
      environment: PIPEDREAM_PROJECT_ENVIRONMENT as ProjectEnvironment,
      credentials: {
        clientId: PIPEDREAM_CLIENT_ID!,
        clientSecret: PIPEDREAM_CLIENT_SECRET!,
      },
    });
}

async createPipedreamToken(workspaceId: string) {
    const token = await this.pd.createConnectToken({
      external_user_id: workspaceId,
      allowed_origins: [
        'http://localhost:8083'
      ],
    });
    return token;
  }

I tried updating the sdk to the latest version (^1.3.3), adding/removing the allowed origins, switching between production and development environments, rotating the client secret – none of these worked

Do you see this call in your network tab?

https://api.pipedream.com/v1/connect/tokens/.../validate...

If so, the response may contain some more info on the error.

If you set your env to development we also sometimes surface more debug info on that auth screen, that might be helpful

When in production, we hide all those errors, since they won’t be useful for your end users.

"oauth_app_id": null,
    "success_redirect_uri": null,
    "error_redirect_uri": null,
    "success": false,
    "error": "The Pipedream Connect token is invalid. Please generate a new one and try again.",
    "project_environment": "development",
    "project_app_name": null,
    "project_support_email": null,
    "project_id": "proj_ddsPejA"

Got this after switching to development

Tagging my team mate for visibility

I’m a little confused about the external_user_id naming, both the param (camel vs snake casing) and the value you’re defining for it. Not positive that’s the issue, but that stood out to me.

Are you able to add some logging to help debug? For example, what values are you actually passing in connectAccount?

Thank you! I found the issue. I was passing the wrong oauthAppId.

Ah hah, nice. Yea, too bad we weren’t able to raise that error more explicitly

What are you building, by the way?

Yea, too bad we weren’t able to raise that error more explicitly
Thanks, no prob. The “token is invalid” error is definitely more appropriate in this case.

What are you building, by the way?
We building AI agents for marketing automation. Pipedream will help us call CRM APIs such as on Hubspot. :slightly_smiling_face:

Nice! And how are you actually using the auth? Curious to hear more about your implementation after the account connection.

We’d like our business users to be able to use the AI agents to automate email replies and lead generation. For this the agents need to autonomously call email & CRM APIs.

The idea is to let users connect their apps using Pipedream, and use the auth to make API calls. The api params will be generated by the AI dynamically (GPT function calls).

Let me know if this is a valid use of Pipedream (seems like a common use case these days).

Yea, totally. Are you planning to retrieve and store tokens for your end users from Pipedream, then send the calls directly to the downstream API from your app?

That’s a perfect use case for the Connect Proxy, which we just shipped: GitHub

Lets you avoid touching any user tokens at all — you can still use an LLM to write the request automatically, send it to the proxy, we’ll insert the user’s auth, then forward it along to the downstream API.

Great, thanks! I’ll check it out.

I wasn’t intending to store tokens. I want to use stored actions and have Pipedream store/manage the token.

I was using pd.runAction(actionId, userId, configuredProps) before.

I wrote the initial code a couple of months ago and haven’t tested that flow in a while.