-
-
Couldn't load subscription status.
- Fork 140
Multi-factor authentication #796
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
base: master
Are you sure you want to change the base?
Changes from all commits
c9c4453
b529529
b2c250b
b38f162
5eb219d
c2baa53
f9e08bc
a23142f
c44bd59
dfd2623
2b3ccc5
04807f4
09ee967
23d5dcb
58083a1
035e1ae
52ac287
1d0a390
e64c265
06c8d67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| version: '3' | ||
| services: | ||
| mongo: | ||
| image: mongo | ||
| ports: | ||
| - "27017:27017" | ||
| redis: | ||
| image: redis | ||
| ports: | ||
| - "6379:6379" | ||
| postgres: | ||
| image: postgres | ||
| ports: | ||
| - "5432:5432" | ||
| environment: | ||
| - POSTGRES_USER=postgres | ||
| - POSTGRES_DB=accounts-js-tests-e2e |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Accounts performMfaChallenge throws error when no mfaToken exists in storage: mfaToken-not-available 1`] = `[Error: mfaToken is not available in storage]`; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`DatabaseManager configuration without MFA createMfaLoginAttempt should throw error 1`] = `"No mfaLoginAttemptsStorage defined for manager"`; | ||
|
|
||
| exports[`DatabaseManager configuration without MFA getMfaLoginAttempt should throw error 1`] = `"No mfaLoginAttemptsStorage defined for manager"`; | ||
|
|
||
| exports[`DatabaseManager configuration without MFA removeMfaLoginAttempt should throw error 1`] = `"No mfaLoginAttemptsStorage defined for manager"`; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,21 @@ | ||
| import { DatabaseInterface, DatabaseInterfaceSessions } from '@accounts/types'; | ||
| import { | ||
| DatabaseInterface, | ||
| DatabaseInterfaceSessions, | ||
| DatabaseInterfaceMfaLoginAttempts, | ||
| } from '@accounts/types'; | ||
|
|
||
| import { Configuration } from './types/configuration'; | ||
|
|
||
| export class DatabaseManager implements DatabaseInterface { | ||
| private userStorage: DatabaseInterface; | ||
| private sessionStorage: DatabaseInterface | DatabaseInterfaceSessions; | ||
| private mfaLoginAttemptsStorage?: DatabaseInterface | DatabaseInterfaceMfaLoginAttempts; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a required field? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidyaha pointed out that people might not want |
||
|
|
||
| constructor(configuration: Configuration) { | ||
| this.validateConfiguration(configuration); | ||
| this.userStorage = configuration.userStorage; | ||
| this.sessionStorage = configuration.sessionStorage; | ||
| this.mfaLoginAttemptsStorage = configuration.mfaLoginAttemptsStorage; | ||
| } | ||
|
|
||
| private validateConfiguration(configuration: Configuration): void { | ||
|
|
@@ -154,4 +160,25 @@ export class DatabaseManager implements DatabaseInterface { | |
| public get setUserDeactivated(): DatabaseInterface['setUserDeactivated'] { | ||
| return this.userStorage.setUserDeactivated.bind(this.userStorage); | ||
| } | ||
|
|
||
| public get createMfaLoginAttempt(): DatabaseInterface['createMfaLoginAttempt'] { | ||
| if (!this.mfaLoginAttemptsStorage) { | ||
| throw new Error('No mfaLoginAttemptsStorage defined for manager'); | ||
| } | ||
| return this.mfaLoginAttemptsStorage.createMfaLoginAttempt.bind(this.mfaLoginAttemptsStorage); | ||
| } | ||
|
|
||
| public get getMfaLoginAttempt(): DatabaseInterface['getMfaLoginAttempt'] { | ||
| if (!this.mfaLoginAttemptsStorage) { | ||
| throw new Error('No mfaLoginAttemptsStorage defined for manager'); | ||
| } | ||
| return this.mfaLoginAttemptsStorage.getMfaLoginAttempt.bind(this.mfaLoginAttemptsStorage); | ||
| } | ||
|
|
||
| public get removeMfaLoginAttempt(): DatabaseInterface['removeMfaLoginAttempt'] { | ||
| if (!this.mfaLoginAttemptsStorage) { | ||
| throw new Error('No mfaLoginAttemptsStorage defined for manager'); | ||
| } | ||
| return this.mfaLoginAttemptsStorage.removeMfaLoginAttempt.bind(this.mfaLoginAttemptsStorage); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| import { DatabaseInterface, DatabaseInterfaceSessions } from '@accounts/types'; | ||
| import { | ||
| DatabaseInterface, | ||
| DatabaseInterfaceSessions, | ||
| DatabaseInterfaceMfaLoginAttempts, | ||
| } from '@accounts/types'; | ||
|
|
||
| export interface Configuration { | ||
| userStorage: DatabaseInterface; | ||
| sessionStorage: DatabaseInterface | DatabaseInterfaceSessions; | ||
| mfaLoginAttemptsStorage?: DatabaseInterface | DatabaseInterfaceMfaLoginAttempts; | ||
| } |
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.
Why don't we return the mfaToken there?
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.
mainly, to simplify the usage