-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Multi-factor authentication #796
Open
ozsay
wants to merge
20
commits into
accounts-js:master
Choose a base branch
from
ozsay:mfa
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c9c4453
work on mfa
ozsay b529529
Merge branch 'master' of github.com:accounts-js/accounts into mfa
ozsay b2c250b
continue working on mfa
ozsay b38f162
add typeorm implementation
ozsay 5eb219d
fix client-password
ozsay c2baa53
fix graphql-client
ozsay f9e08bc
fix accounts-boost
ozsay a23142f
fixed e2e tests and graphql client
ozsay c44bd59
mistake
ozsay dfd2623
fix examples
ozsay 2b3ccc5
add accounts-server tests
ozsay 04807f4
increase coverage
ozsay 09ee967
fixes of CR
ozsay 23d5dcb
remove graphql schema from client code
ozsay 58083a1
Merge branch 'master' of github.com:accounts-js/accounts into mfa
ozsay 035e1ae
Merge branch 'master' into mfa
davidyaha 52ac287
add typing to resolver
ozsay 1d0a390
Merge branch 'mfa' of github.com:ozsay/accounts into mfa
ozsay e64c265
Merge branch 'master' of github.com:accounts-js/accounts into mfa
ozsay 06c8d67
fix lock
ozsay 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 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,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 |
This file contains 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 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
3 changes: 3 additions & 0 deletions
3
packages/client/__tests__/__snapshots__/accounts-client.ts.snap
This file contains 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,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]`; |
This file contains 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 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 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
7 changes: 7 additions & 0 deletions
7
packages/database-manager/__tests__/__snapshots__/database-manager.ts.snap
This file contains 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,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"`; |
This file contains 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 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 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 |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -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; | ||
} |
This file contains 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.
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.
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