Skip to content
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

Posting Authority check before logging in #8

Merged
merged 2 commits into from Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/repositories/hive/hive.repository.ts
Expand Up @@ -148,4 +148,18 @@ export class HiveRepository {
PrivateKey.fromString(process.env.DELEGATED_ACCOUNT_POSTING),
)
}

async verifyPostingAuth(account: any) {
let doWe = false
if (Array.isArray(account.posting.account_auths)) {
account.posting.account_auths.forEach(function (item) {
if (item[0] === 'threespeak') {
doWe = true
}
})
return doWe
} else {
return false
}
}
}
12 changes: 11 additions & 1 deletion src/services/auth/auth.controller.ts
Expand Up @@ -63,7 +63,17 @@ export class AuthController {
this.hiveRepository.verifyHiveMessage(cryptoUtils.sha256(JSON.stringify(proof_payload)), body.proof, accountDetails) &&
new Date(proof_payload.ts) > moment().subtract('1', 'minute').toDate() //Extra safety to prevent request reuse
) {
return await this.authService.authenticateUser(proof_payload.account)
if (this.hiveRepository.verifyPostingAuth(accountDetails)) {
return await this.authService.authenticateUser(proof_payload.account)
} else {
throw new HttpException(
{
reason: `Hive Account @${proof_payload.account} has not granted posting authority to @threespeak`,
errorType: "MISSING_POSTING_AUTHORITY"
},
HttpStatus.BAD_REQUEST,
)
}
} else {
throw new HttpException(
{
Expand Down