-
Notifications
You must be signed in to change notification settings - Fork 88
Add async registration flow for devices #7820
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e747383
Add plain layout
knolleary ff2058c
Add AsyncLoginSession model
knolleary c1d238a
Add device async registration flow
knolleary b8c7cc9
Add async device registration flow
knolleary 5f51877
Add index for doneToken
knolleary 34bf5f7
Tidy up misc items from review
knolleary 6ccb981
Change async result to Text rather than String
knolleary ad6d3c4
Tidy up some unused code from the views
knolleary 5464da3
Support for a small scale spinner
knolleary 87d8c79
Fix router link on feature unavailable banner
knolleary 262a632
Add limits check on device step
knolleary da94332
Add billing info if applicable
knolleary 05b63a8
Merge branch 'main' into 7731-asyncsession-api
knolleary ed3eea1
Tidy up of registration page
knolleary fa1619b
Update types
knolleary 9e41703
Merge branch 'main' into 7731-asyncsession-api
knolleary fbb08b5
Ensure errors during device creation are reflected in AsyncSesssion
knolleary 5090e0d
Remove expired tokens
knolleary ca75095
Update migration file to latest
knolleary f502e83
Update lockfile
knolleary 5b7f6cb
Fix linting
knolleary a8d9027
Fix linting
knolleary ba78c44
Add rate limiting to public registration end point
knolleary 5a94edb
Add home link to plain layout
knolleary cbf0687
Merge branch 'main' into 7731-asyncsession-api
knolleary 87eba46
Update package file
knolleary d9f4109
Revert lock file changes
knolleary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| const { DataTypes } = require('sequelize') | ||
|
|
||
| module.exports = { | ||
| /** | ||
| * upgrade database | ||
| * @param {QueryInterface} context Sequelize.QueryInterface | ||
| */ | ||
| up: async (context, Sequelize) => { | ||
| await context.createTable('AsyncLoginSessions', { | ||
| sessionToken: { | ||
| type: DataTypes.STRING, | ||
| primaryKey: true | ||
| }, | ||
| doneToken: { | ||
| type: DataTypes.STRING | ||
| }, | ||
| status: { | ||
| type: DataTypes.STRING, | ||
| defaultValue: 'pending' | ||
| }, | ||
| result: { | ||
| type: DataTypes.TEXT | ||
| }, | ||
| createdAt: { | ||
| type: DataTypes.DATE, | ||
| allowNull: false | ||
| }, | ||
| updatedAt: { | ||
| type: DataTypes.DATE, | ||
| allowNull: false | ||
| } | ||
| }) | ||
| await context.addIndex('AsyncLoginSessions', { name: 'async_login_sessions_done_token', fields: ['doneToken'] }) | ||
| }, | ||
| down: async (context, Sequelize) => { } | ||
|
knolleary marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| const { DataTypes } = require('sequelize') | ||
|
|
||
| const { generateToken } = require('../utils') | ||
|
|
||
| async function validateSessionExpiry (session) { | ||
| if (session) { | ||
| const age = Date.now() - session.createdAt.getTime() | ||
| if (age > 1000 * 60 * 30) { | ||
| // session is older than 30 minutes, expire it | ||
| await session.destroy() | ||
|
knolleary marked this conversation as resolved.
|
||
| return null | ||
| } | ||
| } | ||
| return session | ||
| } | ||
|
|
||
| module.exports = { | ||
| name: 'AsyncLoginSession', | ||
| schema: { | ||
| sessionToken: { | ||
| type: DataTypes.STRING, | ||
| primaryKey: true | ||
| }, | ||
| doneToken: { | ||
| type: DataTypes.STRING | ||
| }, | ||
| status: { | ||
| type: DataTypes.STRING, | ||
| defaultValue: 'pending' | ||
| }, | ||
| result: { | ||
| type: DataTypes.TEXT | ||
| } | ||
| }, | ||
| indexes: [ | ||
| { name: 'async_login_sessions_done_token', fields: ['doneToken'] } | ||
| ], | ||
| finders: function (M) { | ||
| return { | ||
| static: { | ||
| createToken: async () => { | ||
| const sessionToken = generateToken(16) | ||
| const doneToken = generateToken(32) | ||
| const session = await this.create({ | ||
| sessionToken, | ||
| doneToken | ||
| }) | ||
| return session | ||
| }, | ||
| bySessionToken: async (sessionToken) => { | ||
| const session = await this.findOne({ | ||
| where: { sessionToken } | ||
| }) | ||
| return validateSessionExpiry(session) | ||
| }, | ||
| getAndExpireByDoneToken: async (doneToken) => { | ||
| let session = await this.findOne({ | ||
| where: { doneToken } | ||
| }) | ||
| session = await validateSessionExpiry(session) | ||
| if (session && session.status !== 'pending') { | ||
| // The session is resolved. We only allow retrieving it once, | ||
| // so we destroy it after retrieval. | ||
| await session.destroy() | ||
| } | ||
| return session | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.