mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 16:14:43 -04:00
private: fixed token generation bugs
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
c232707a89
commit
97f7128355
1 changed files with 8 additions and 3 deletions
|
@ -39,19 +39,24 @@ export class UsersService {
|
||||||
): Promise<AuthToken> {
|
): Promise<AuthToken> {
|
||||||
const user = await this.getUserByUsername(userName);
|
const user = await this.getUserByUsername(userName);
|
||||||
let accessToken = '';
|
let accessToken = '';
|
||||||
|
let randomString = '';
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
try {
|
try {
|
||||||
const randomString = crypt.randomBytes(64).toString();
|
randomString = crypt.randomBytes(64).toString("base64");
|
||||||
accessToken = await this.hashPassword(randomString);
|
accessToken = await this.hashPassword(randomString);
|
||||||
await this.getUserByAuthToken(accessToken);
|
await this.getUserByAuthToken(accessToken);
|
||||||
} catch (NotInDBError) {
|
} catch (NotInDBError) {
|
||||||
const token = AuthToken.create(user, identifier, accessToken);
|
const token = AuthToken.create(user, identifier, accessToken);
|
||||||
return this.authTokenRepository.save(token);
|
const createdToken = this.authTokenRepository.save(token);
|
||||||
|
return {
|
||||||
|
accessToken: randomString,
|
||||||
|
...createdToken
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// This should never happen
|
// This should never happen
|
||||||
throw new RandomnessError(
|
throw new RandomnessError(
|
||||||
'You machine is not able to generate not-in-use tokens. This should never happen.',
|
'Your machine is not able to generate not-in-use tokens. This should never happen.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue