-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix store invite #113
Merged
Merged
Fix store invite #113
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4d5bc0
fix: invite link idea
Mathixx 1568a24
feat : added invitationTokens table + an index on address (and reorde…
h1ppox99 2f32a23
feat : added new management of pending invitations - created invitati…
h1ppox99 1e9047e
fix : added TODO concerning call to the onbind api
h1ppox99 8a0dda1
fix: added link to invite message
Mathixx 0724eb7
feat : added msisdn in the suppported media for store-invite
h1ppox99 241ec9e
fix : added a field phone
h1ppox99 3553be7
fix: invitation link is now created using link designated in server c…
Mathixx 4a60f3a
fix: put invitation_server_name parameter as optional
Mathixx 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
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
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
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
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
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 |
---|---|---|
|
@@ -10,48 +10,51 @@ export type SupportedDatabases = 'sqlite' | 'pg' | |
|
||
export type Collections = | ||
| 'accessTokens' | ||
| 'oneTimeTokens' | ||
| 'activeContacts' | ||
| 'attempts' | ||
| 'keys' | ||
| 'oneTimeTokens' | ||
| 'hashes' | ||
| 'invitationTokens' | ||
| 'keys' | ||
| 'longTermKeypairs' | ||
| 'mappings' | ||
| 'privateNotes' | ||
| 'roomTags' | ||
| 'userHistory' | ||
| 'userQuotas' | ||
| 'mappings' | ||
| 'longTermKeypairs' | ||
| 'shortTermKeypairs' | ||
| 'userHistory' | ||
| 'userPolicies' | ||
| 'activeContacts' | ||
| 'userQuotas' | ||
|
||
const cleanByExpires: Collections[] = ['oneTimeTokens', 'attempts'] | ||
|
||
const tables: Record<Collections, string> = { | ||
accessTokens: 'id varchar(64) PRIMARY KEY, data text', | ||
oneTimeTokens: 'id varchar(64) PRIMARY KEY, expires int, data text', | ||
activeContacts: 'userId text PRIMARY KEY, contacts text', | ||
attempts: 'email text PRIMARY KEY, expires int, attempt int', | ||
keys: 'name varchar(32) PRIMARY KEY, data text', | ||
oneTimeTokens: 'id varchar(64) PRIMARY KEY, expires int, data text', | ||
hashes: | ||
'hash varchar(48) PRIMARY KEY, pepper varchar(32), type varchar(8), value text, active integer', | ||
invitationTokens: 'id varchar(64) PRIMARY KEY, address text, data text', | ||
keys: 'name varchar(32) PRIMARY KEY, data text', | ||
longTermKeypairs: | ||
'name text PRIMARY KEY, keyID varchar(64), public text, private text', | ||
mappings: | ||
'client_secret varchar(255) PRIMARY KEY, session_id varchar(12), medium varchar(8), valid integer, address text, submit_time integer, send_attempt integer', | ||
privateNotes: | ||
'id varchar(64) PRIMARY KEY, authorId varchar(64), content text, targetId varchar(64)', | ||
roomTags: | ||
'id varchar(64) PRIMARY KEY, authorId varchar(64), content text, roomId varchar(64)', | ||
userHistory: 'address text PRIMARY KEY, active integer, timestamp integer', | ||
userQuotas: 'user_id varchar(64) PRIMARY KEY, size int', | ||
mappings: | ||
'client_secret varchar(255) PRIMARY KEY, session_id varchar(12), medium varchar(8), valid integer, address text, submit_time integer, send_attempt integer', | ||
longTermKeypairs: | ||
'name text PRIMARY KEY, keyID varchar(64), public text, private text', | ||
shortTermKeypairs: | ||
'keyID varchar(64) PRIMARY KEY, public text, private text, active integer', | ||
userHistory: 'address text PRIMARY KEY, active integer, timestamp integer', | ||
userPolicies: 'user_id text, policy_name text, accepted integer', | ||
activeContacts: 'userId text PRIMARY KEY, contacts text' | ||
userQuotas: 'user_id varchar(64) PRIMARY KEY, size int' | ||
} | ||
|
||
const indexes: Partial<Record<Collections, string[]>> = { | ||
oneTimeTokens: ['expires'], | ||
attempts: ['expires'], | ||
invitationTokens: ['address'], | ||
oneTimeTokens: ['expires'], | ||
userHistory: ['timestamp'] | ||
} | ||
|
||
|
@@ -563,6 +566,57 @@ class IdentityServerDb<T extends string = never> | |
return this.createOneTimeToken(data, expires) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/promise-function-async | ||
createInvitationToken(address: string, data: object): Promise<string> { | ||
/* istanbul ignore if */ | ||
if (this.db == null) { | ||
throw new Error('Wait for database to be ready') | ||
} | ||
const id = randomString(64) | ||
return new Promise((resolve, reject) => { | ||
this.db | ||
.insert('invitationTokens', { | ||
id, | ||
address, | ||
data: JSON.stringify(data) | ||
}) | ||
.then(() => { | ||
this.logger.info(`Invitation token created for ${address}`) | ||
resolve(id) | ||
}) | ||
.catch((err) => { | ||
/* istanbul ignore next */ | ||
this.logger.error('Failed to insert token', err) | ||
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. Missing "reject": a promise must always call resolve or reject |
||
reject(err) | ||
}) | ||
}) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/promise-function-async | ||
verifyInvitationToken(id: string): Promise<object> { | ||
/* istanbul ignore if */ | ||
if (this.db == null) { | ||
throw new Error('Wait for database to be ready') | ||
} | ||
return new Promise((resolve, reject) => { | ||
this.db | ||
.get('invitationTokens', ['data', 'address'], { id }) | ||
.then((rows) => { | ||
/* istanbul ignore else */ | ||
if (rows.length > 0) { | ||
resolve(JSON.parse(rows[0].data as string)) | ||
} else { | ||
reject(new Error('Unknown token')) | ||
} | ||
}) | ||
.catch((e) => { | ||
/* istanbul ignore next */ | ||
this.logger.error('Failed to get token', e) | ||
reject(e) | ||
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. Add logger.error ? |
||
}) | ||
}) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/promise-function-async | ||
verifyToken(id: string): Promise<object> { | ||
/* istanbul ignore if */ | ||
|
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.
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.
Check notice
Code scanning / devskim
A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note