Using dynamic values in OAuth 2.0 connection

I'm just starting to explore OAuth connections within my apps and running into some issues.

My goal is to allow users of a public app to OAuth to Google, then run a query to get a report from the YouTube Analytics API about the connected channel.

I was able to successfully connect using Retool's Authenticate with Google APIs using OAuth 2.0 instructions, but I'm running into issues when trying to pass dynamic values to the request so that the time period is based on the timing of the user's OAuth connection. Not sure if it's because I'm doing something incorrectly or what I'm trying to do is just not possible with Retool.

Here's what I've got so far:

Thanks for the help in advance!

well, that's odd. just to rule things out, does using
{{ moment().format('YYYY-MM-DD') }}
and
{{ moment().subtract(30, 'days').format('YYYY-MM-DD') }}
produce the same results?

Thanks the reply @bobthebear. Unfortunately, still seems to be the same :confused:
Screenshot 2024-06-21 at 10.00.50 AM

Screenshot 2024-06-21 at 9.59.38 AM

Hi there,

We have a feature request in our backlog for allowing custom Javascript or dynamic variables in resource configurations. I'll post here if that becomes prioritized.

Custom auth does have an option for adding Javascript steps though. You could try recreating the Oauth2 flow in custom auth and add a Javascript step + a custom defined variable.

Do you need the values hardcoded in the resource config? If not, you could remove them from the resource and set them dynamically on the app query

One note with your use case is that resources that per-user authentication (e.g., Google Sheets, OAuth, custom auth, etc) prevent apps from being shared publicly.

thanks for the reply @Tess!

Custom auth does have an option for adding Javascript steps though. You could try recreating the Oauth2 flow in custom auth and add a Javascript step + a custom defined variable.

I attempted this, but I'm getting the following error:


Not sure if it's because the {{ moment }} is also still getting passed to the request. Here's what my flow looks like:

One note with your use case is that resources that per-user authentication (e.g., Google Sheets, OAuth, custom auth, etc) prevent apps from being shared publicly.

That's unfortunate, as the app being semi-public (i.e., a specific user can access their specific state/instance of the app) is a necessity for my use case. Is there any workaround where I could pass that oauth'd data to my database resource?

Hi @eman31,

For the variables, you'd want to add a Javascript step first, to process the date JS, then pass that JS result to a variable.

It looks like the API request at the end should be filled in on the resource level, rather than in the Custom Auth section

Are there specific scopes you need to list? The OAuth2 Generic option has a field for scopes.

As long as the user is logged in to Retool when they use the app, they should be able to access the authenticated resource (assuming they have permission)

@Tess, gotcha. It looks like the moment library isn't accessible?

It looks like the API request at the end should be filled in on the resource level, rather than in the Custom Auth section

If this is the case, then based on this...

We have a feature request in our backlog for allowing custom Javascript or dynamic variables in resource configurations. I'll post here if that becomes prioritized.

It seems like I won't be able to dynamically change the date, is that correct?

Anyway, without the Javascript, when testing the flow, once I authorize, I get directed to "https://oauth.retool.com/oauth/redirectToIdp" that just says "Found. Redirecting to". Am I missing something else from there?

Right, libraries aren't supported yet! :disappointed: We have a feature request for this in our backlog

1 Like

:thinking: Are you passing the auth token to the base url headers?

Yes, it should be. See below for the full settings: