Skip to content

Commit

Permalink
Feat/enhance-registration-login-flow (#1140)
Browse files Browse the repository at this point in the history
# Feat: Enhance Registration and Login Flows

## JIRA Ticket

[BSS-313](https://jira.csiro.com/browse/BSS-313)

## Description

Overall goal is to provide a more seamless registration workflow for new
users invited to a notebook. Will also try to improve the overall login
experience.

## Proposed Changes

- [x] Modify the login flow to use redirects back to the app rather than
pop-up windows (on web)
- [x] Use redirect on mobile back to a custom URL scheme to make login
more seamless
- [x] Make registration use the redirect scheme as well so that it can
be used from in app
- [x] Change registration invite ids to short codes - six character
codes with a fixed prefix (BSS-123-ABC) so that they can be entered by
hand
- [ ] Invite codes should be fixed for each role in the notebook rather
than being generated on demand
- [x] Add QR code scan option from in the app to register for a notebook
- [x] Add option to enter short-code in app to register for a notebook
- [x] Tidy up login for Conductor web interface so that it works with
new redirect scheme


## How to Test

Add configuration to the api:

```javascript
CONDUCTOR_SHORT_CODE_PREFIX="DEV"
```

You'll need to be running both the api and the app to test. On the app
do a 'Wipe and Reset Everything' from About Build to clear local
databases.

### Conductor

- Login to conductor should be as before but instead of being taken to
the 'send-token' page you should go to the home page after login. The
return to app button is removed.

### Login/logout
 
- Go to the conductor (API) URL and make sure you are not logged in
- In the app, click 'Sign in" on the login page, you will be redirected
to Conductor to login, once login is successful you will be redirected
back and should be properly logged in
- Check that the username is shown in the top right. Note that the menu
is now gone and the button just links back to the sign-in page
- Logout from the app, you may notice a quick redirect but it should log
out as before, however now you are also logged out from conductor (visit
the conductor URL to verify)

### Short code registration

- In Conductor, select a notebook and generate an invite, select a user
role (eg. admin)
- Copy the short code that is generated, note the prefix (as configured
above)
- Logout of conductor
- In the app, enter the six character short code (without prefix), click
Register
- You should see the registration screen, enter account details to make
a new account
- Once you submit, you should be redirected back to the app and (after a
delay) the notebook should be available to you
- Enter a random string of characters and you should get an error page
from conductor with a button to return to the app

### QR Code registration

This is only available on Android or IOS

- As before, generate an invite for a notebook, this time display the QR
Code
- In the app, select 'Scan QR Code' from the sign in page
- Scan the QR code, it should take you to the registration page or if
already logged in, just make the notebook available
- Scan a random QR code/barcode and you should get an error message
 
## Checklist

- [x] I have confirmed all commits have been signed.
- [x] I have added JSDoc style comments to any new functions or classes.
- [x] Relevant documentation such as READMEs, guides, and class comments
are updated.
  • Loading branch information
stevecassidy authored Sep 26, 2024
2 parents 5dd2e8b + cdaa882 commit 86aaf34
Show file tree
Hide file tree
Showing 56 changed files with 1,059 additions and 777 deletions.
1 change: 1 addition & 0 deletions api/.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PROFILE_NAME=local-dev
# Public name and short description for this instance
CONDUCTOR_INSTANCE_NAME="Development FAIMS Server"
CONDUCTOR_DESCRIPTION="Development server on localhost"
CONDUCTOR_SHORT_CODE_PREFIX="DEV"

# couchdb configuration
COUCHDB_USER=admin
Expand Down
119 changes: 92 additions & 27 deletions api/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string"
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}
Expand All @@ -56,6 +60,26 @@
}
}
},
"/info": {
"get": {
"summary": "Get information",
"description": "Provides details of the server such as name and description",
"produces": ["application/json"],
"security": {"Auth": []},
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/definitions/ListingsObject"
}
}
}
}
}
}
},
"/notebooks/": {
"get": {
"summary": "Get a list of notebooks",
Expand All @@ -66,10 +90,14 @@
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/NotebookMeta",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/NotebookMeta",
}
}
}
}
},
Expand Down Expand Up @@ -116,8 +144,12 @@
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Notebook"
"content": {
"application/json": {
"schema": {
"$ref": "#/definitions/Notebook"
}
}
}
},
"401": {
Expand Down Expand Up @@ -154,8 +186,12 @@
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Notebook"
"content": {
"application/json": {
"schema": {
"$ref": "#/definitions/Notebook"
}
}
}
},
"401": {
Expand Down Expand Up @@ -183,10 +219,14 @@
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/RecordList",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/RecordList",
}
}
}
}
},
Expand Down Expand Up @@ -221,10 +261,7 @@
"security": {"Auth": []},
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "string"
}
"description": "successful operation"
},
"401": {
"$ref": "#/components/responses/UnauthorizedError"
Expand Down Expand Up @@ -288,10 +325,14 @@
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/UserList",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/UserList",
}
}
}
}
},
Expand Down Expand Up @@ -379,8 +420,12 @@
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/UserList"
"content": {
"application/json": {
"schema": {
"$ref": "#/definitions/UserList"
}
}
}
},
"401": {
Expand All @@ -391,6 +436,26 @@
}
},
"definitions": {
"ListingsObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"conductor_url": {
"type": "string"
},
"description": {
"type": "string"
},
"prefix": {
"type": "string"
}
}
},
"NotebookMeta": {
"type": "object",
"properties": {
Expand Down
8 changes: 5 additions & 3 deletions api/src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ import {
CONDUCTOR_DESCRIPTION,
CONDUCTOR_INSTANCE_NAME,
CONDUCTOR_PUBLIC_URL,
CONDUCTOR_SHORT_CODE_PREFIX,
DEVELOPER_MODE,
NOTEBOOK_CREATOR_GROUP_NAME,
} from '../buildconfig';
import {createManyRandomRecords} from '../couchdb/devtools';
import {restoreFromBackup} from '../couchdb/backupRestore';
import {ListingInformation} from '@faims3/data-model';
import {ListingsObject} from '@faims3/data-model';

// TODO: configure this directory
const upload = multer({dest: '/tmp/'});
Expand All @@ -83,12 +84,13 @@ api.post('/initialise/', async (req, res) => {
/**
* Handle info requests, basic identifying information for this server
*/
api.get('/info', async (req, res) => {
const info: ListingInformation = {
api.get<{}, ListingsObject>('/info', async (req, res) => {
const info: ListingsObject = {
id: slugify(CONDUCTOR_INSTANCE_NAME),
name: CONDUCTOR_INSTANCE_NAME,
conductor_url: CONDUCTOR_PUBLIC_URL,
description: CONDUCTOR_DESCRIPTION,
prefix: CONDUCTOR_SHORT_CODE_PREFIX,
};
res.json(info);
});
Expand Down
6 changes: 6 additions & 0 deletions api/src/auth_providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ const AVAILABLE_AUTH_PROVIDERS: {[name: string]: any} = {
google: google_get_strategy,
};

/**
* Register auth providers using `passport.use`,
* provider identifiers must appear in the AVAILABLE_AUTH_PROVIDERS above
*
* @param providers_to_use array of provider identifiers
*/
export function add_auth_providers(providers_to_use: string[]) {
for (const provider_name of providers_to_use) {
const provider_gen = AVAILABLE_AUTH_PROVIDERS[provider_name];
Expand Down
Loading

0 comments on commit 86aaf34

Please sign in to comment.