-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor demo to refresh token automatically #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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()}` |
There was a problem hiding this comment.
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.
There was a problem hiding this 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)
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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. |
closing in favor of #11 |
This PR does two things:
EmbeddedWidget
to add anupdateToken()
methodThe way the demo does the token refreshing is unsafe for a production application, because we are exposing the
client_id
andclient_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 thedemo/.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 theirclient_id
andclient_secret
directly.