-
Goal: I am implementing custom OAuth because I need to access a query parameter in the redirect URL.
-
Steps: I implemented custom OAuth which works as expected. However, I am not sure what data I have access to in the Define a variable step. Is there documentation on this? What should the variable definition be to get the query parameter data? If that's not possible, what other options exist to retrieve that data from the redirect URL?
Hey @bradycaspar - Happy to try and get a solution for you here. Can you help understand what you're looking to do with the query parameter in the redirect URL? i.e. Where you're trying to access it and for what need?
Hey Andrew, thanks for the response! The long version is that we are integrating with the Quickbooks API and in the oauth redirect, we need to access the realmId
query param. You can see the docs for this here: Intuit Developer.
My approach currently is to use the 'Define a variable' step to try and extract this data from the redirect. Below is a screenshot from the debugger when completing oauth. As you can see, the URL is the callback URL defined in Retool, format https://oauth.retool.com/oauth/user/oauthcallback
, and the realmId
query param is appended by the Quickbooks API. This is the value we need to extract from this callback.
How would we access this?
Thanks for the additional information. This looks like a standard OAuth 2.0 flow except for that realmId, so you're right in needing to use Custom Auth, as we don't expose urlParameters for our standard OAuth 2.0 auth type.
There are two options that should work:
- Start with the step of "Redirect to SSO" which will give you access the the urlparams, then "Define a variable" to use in the resource itself. From there build out the rest of the flow using "API request".
- Another option, which could work is if you only need to handle one company in QuickBooks, is to get your realmId and hardcode it.
You could also replace the "API request" step in option 1 with our "OAuth 2.0 (generic)" step, but that would require the user to login twice to Quickbooks.
Let me know if any of these work for you so that we can get some documentation out there for this. I've also created a ticket for us to consider easier ways to enable this implementation need from QuickBooks.
Ok I got the custom auth working! The only thing we are stuck on is how to reference the variable we defined, QB_REALM_ID
variable anywhere in the app outside of the auth flow. Is this possible?
Hey @Andrew_Morse did you have a chance to check this out? Still looking for a little clarification, thank you!
Hey @bradycaspar! Variables defined within the auth flow are stored server-side and can only be referenced within queries to the corresponding resource.
This is the workaround that I've recommended in the past. Let me know if that is applicable to your use case!
@brady Sorry I missed your message from a few days ago. If I'm reading the Quickbooks docs correctly, you need to pull that variable into the URL parameter for this resource, correct?
If so, you shouldn't need the workaround since it's the same resource. You can just put the variable name (no {{}}'s) as the value for the parameter.
Ok we got it! Thank you for walking me through this!
No worries, the way we handle these variables are different than how you reference them elsewhere in the product. I'd love to get a "How To" article created for connecting to Quickbooks.
Did you end up building this with "API Request" steps or "OAuth 2.0 generic"? Would you mind if our technical writing team reaches out if they have questions when putting together documentation around this?
@Andrew_Morse I ended up using the custom auth with Redirect to SSO as the first step and API Request as a later step.
I am happy to help! Feel free to reach out here or in my messages on this platform or direct to my email if you have access to it.
@Andrew_Morse running into another roadblock I could use some input on!
What I need to do:
Access one of the variables defined in the auth resource in a different resource. The auth resource defines a variable called QB_REALM_ID
. This is a user's company id. We need to update Supabase with this id for the user. This is a key component of the app which makes onboarding for the user 10x simpler. Without it, the customer needs to go to their Quickbooks portal, find their company id in their settings, then copy and paste it into our app.
What I have tried:
- Getting auth session data from Quickbooks API, this does not exist
- Update the response to include this variable
return {...data, var: QB_REALM_ID}
- Pass into additional scope of the event handler, which does not appear possible based on this post
- Use Javascript to set a
localStorage
value in the auth resource as the last step. This results in an odd seemingly unrelated error, but I confirmed this step was causing the error:
Is this functionality possible? I don't see why this variable shouldn't be accessible outside of the resource where it is defined.
Hey Brady - Due to the sensitive nature of auth variables we limit how widely they can be accessed. I think the best workaround in your case would be what Darren recommended above which was to use a Workflow with a webhook trigger to store/perform another action, such as updating Supabase.
We are trying this now, looks like it should work, thank you!