Skip to content

Conversation

joeykmh
Copy link
Contributor

@joeykmh joeykmh commented Apr 23, 2025

This PR does two things:

  • Updates the EmbeddedWidget to add an updateToken() method
  • Modifies the demo to use this method and refresh the scoped token automatically

The way the demo does the token refreshing is unsafe for a production application, because we are exposing the client_id and client_secret in the browser. However, I think this is way faster and easier to get up and running with. Users just have to paste in some static values into the demo/.env file and they can use the demo without the session expiring.

We would probably want a short guide somewhere about how to do this more safely in a production environment (e.g. use your own backend to fetch a scoped token for the given user, pass that to your webapp, then call EmbeddedWidget.updateToken(newToken) whenever appropriate. Putting a production-grade implementation in the demo feels excessive, though.

If this approach looks good, I think we can get rid of demo/scripts/dev.js and update the readme to instruct users to use their client_id and client_secret directly.

const { widgetUrl, token } = await getScopedToken();
const originalWidgetUrl = new URL(widgetUrl);
const newWidgetUrl = new URL(
`${import.meta.env.VITE_AB_WEBAPP_URL}${originalWidgetUrl.pathname.toString()}?${originalWidgetUrl.searchParams.toString()}`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to update this to conditionally use VITE_AB_WEBAPP_URL only if it's set.

Copy link
Collaborator

@teallarson teallarson left a comment

Choose a reason for hiding this comment

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

If we do merge this, we need a big fat "Do not use this in production" warning in the README (that said... I'm going to use this branch for what I'm working on locally until I can bring this PR up in standup)

Copy link
Contributor

@girarda girarda left a comment

Choose a reason for hiding this comment

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

this is great! +1 on Teal's ask to clarify the getAdminToken shouldn't be used in a production environment

</div>
<script type="module">
import { EmbeddedWidget } from "@airbyte-embedded/airbyte-embedded-widget";
import { EmbeddedWidget } from "../src/EmbeddedWidget.ts";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have a strong opinion on how we import this... Evan had suggested changing this from directly importing the file to importing it using @airbyte-embedded originally... I am guessing so it's more production-like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I guess this is the tension between "the demo is for dev work" and "the demo is a demo". I find it annoying to have to remember to go change the import path every time I want to work on the EmbeddedWidget.

What if we just move the current demo app into a dev directory, and we keep a more polished demo in the demo directory? That would also allow us to keep all our dev niceties (client side token refreshing, import path, overrides) separate from the actual "demo" that operators might spin up.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a pr introducing a version with a server that solves the token fetching also. Let's do that instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, I split out the .updateToken() method into this PR since your PR does not seem to do that yet: #13

@teallarson
Copy link
Collaborator

With removing the demo.js, the code in the HTML file becomes a lot more complex.

We want that file to be easily digestible for an Operator running a POC of embedded. They won't care about local overrides. IMO the local overrides option should remain separate.

@joeykmh joeykmh changed the title Add EmbeddedWidget.updateToken() method Refactor demo to refresh token automatically Apr 25, 2025
@joeykmh
Copy link
Contributor Author

joeykmh commented Apr 25, 2025

closing in favor of #11

@joeykmh joeykmh closed this Apr 25, 2025
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