Add async registration flow for devices#7820
Conversation
cstns
left a comment
There was a problem hiding this comment.
Looking very good overall, just a few minor nitpicks from me. The most important one is the rate limiter on the registration endpoint.
| const age = Date.now() - session.createdAt.getTime() | ||
| if (age > 1000 * 60 * 30) { | ||
| // session is older than 30 minutes, expire it | ||
| await session.destroy() |
There was a problem hiding this comment.
I feel we should also add a housekeeper task to do a daily cleanup. Some tokens might be created and never used and remain stale.
| <div class="ff-layout--plain"> | ||
| <div class="ff-header"> | ||
| <!-- Mobile: Icon-only logo --> | ||
| <img class="ff-logo lg:hidden" src="/ff-minimal-red.svg" alt="FlowFuse"> |
There was a problem hiding this comment.
this should be wrapped in an anchor link to enable navigation when clicked.
Found myself in a situation where i couldn't navigate back home without altering the url. Also worth adding a home button under the The registration session you are trying to use is invalid or has expired. Please start the registration process again. notice, similar to our 404 pages
| @@ -0,0 +1,261 @@ | |||
| <template> | |||
| <MultiStepForm | |||
| ref="multiStepForm" | |||
There was a problem hiding this comment.
Don't blame the guy using your component 😉 . This has always been the case AFAIK, unless there's some secret sauce I've missed.
There was a problem hiding this comment.
I vaguely remember adding something that allowed you to block particular steps or all of them, I need to check sure
There was a problem hiding this comment.
I added a way to disable the top indicators, but a flag check is tripping it up. I'll raise a separate fix for it
| }) | ||
| }) | ||
|
|
||
| describe.only('Async device registration', async function () { |
| if (this.registrationSession) { | ||
| payload.registrationSession = this.registrationSession | ||
| } | ||
| console.log(payload) |
| <p>Applications are used to manage and group together your Node-RED Instances and resources.</p> | ||
|
|
||
| <div v-if="writableApplications.length > 5" class="search-wrapper flex justify-center my-2"> | ||
| <div v-if="writableApplications.length > 1" class="search-wrapper flex justify-center my-2"> |
There was a problem hiding this comment.
I'm trying to understand why this was shown only if we had more than 5 writ-able applications
There was a problem hiding this comment.
This was the choice someone made in the original form. Presumably, if there are <6, then they are all visible and quick to pick from the list. Only if there is more does the list become harder to manage and the filter is helpful.
There was a problem hiding this comment.
I may be guilty of that, looking at it now it seems to be an arbitrary number
| name: 'ff-layout-plain', | ||
| computed: { | ||
| ...mapState(useUxStore, ['overlay']), | ||
| ...mapState(useProductBrokersStore, ['interview']), |
| @@ -52,25 +52,6 @@ export default { | |||
| ...mapState(useUxStore, ['overlay']), | |||
| ...mapState(useProductBrokersStore, ['interview']), | |||
| ...mapState(useAccountSettingsStore, ['hasAvailableTeams']) | |||
There was a problem hiding this comment.
...mapState(useAccountSettingsStore, ['hasAvailableTeams']) can also be removed as it was only used in the stale block you removed
| meta: { | ||
| title: 'Register Remote Instance', | ||
| layout: 'plain' | ||
| // menu: { |
There was a problem hiding this comment.
we should remove this, there's nowhere to go back from, this was a newly opened page

Closes #7731
This creates an async device registration service that allows a Device Agent to direct a user to a URL to get their device registered, and have the OTC registration code get returned to the device.
We don't have the corresponding Device Agent changes (yet), but to test this PR you can simulate it on the command line.
In these examples, I'm assuming you are testing against a forge app running on
localhost:3000- you'll need to adjusted the hostname/port as appropriate.Start an async registration:
This will return an JSON object with
registerUrlanddoneUrl. Note they are actually paths rather than full URLs.Open
registerUrlin your browser. It will take you through the device registration process. At the end, it shows you the OTC for the newly registered device.Poll the
doneUrlin the background - it will return202status code whilst the registration process is in progress. Once the device has been registered, this url will return200with theotcin the payload object. It will only do this once - subsequent requests will 404.I have added UTs for the backend apis that cover all the interactions with the API. I have not done any UI Test coverage.
There are a couple items outstanding (that may be follow up PRs)