mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
Merge pull request #1329 from gradido/fix_rejected_login
fix_rejected_login
This commit is contained in:
commit
ebb7807d7f
@ -8,16 +8,28 @@ import { RIGHTS } from '../../auth/RIGHTS'
|
|||||||
import { ServerUserRepository } from '../../typeorm/repository/ServerUser'
|
import { ServerUserRepository } from '../../typeorm/repository/ServerUser'
|
||||||
import { getCustomRepository } from 'typeorm'
|
import { getCustomRepository } from 'typeorm'
|
||||||
import { UserRepository } from '../../typeorm/repository/User'
|
import { UserRepository } from '../../typeorm/repository/User'
|
||||||
|
import { INALIENABLE_RIGHTS } from '../../auth/INALIENABLE_RIGHTS'
|
||||||
|
|
||||||
const isAuthorized: AuthChecker<any> = async ({ context }, rights) => {
|
const isAuthorized: AuthChecker<any> = async ({ context }, rights) => {
|
||||||
context.role = ROLE_UNAUTHORIZED // unauthorized user
|
context.role = ROLE_UNAUTHORIZED // unauthorized user
|
||||||
|
|
||||||
// Do we have a token?
|
// Do we have a token?
|
||||||
if (context.token) {
|
if (context.token) {
|
||||||
|
// Decode the token
|
||||||
const decoded = decode(context.token)
|
const decoded = decode(context.token)
|
||||||
if (!decoded) {
|
if (!decoded) {
|
||||||
// we always throw on an invalid token
|
// Are all rights requested public?
|
||||||
throw new Error('403.13 - Client certificate revoked')
|
const isInalienable = (<RIGHTS[]>rights).reduce(
|
||||||
|
(acc, right) => acc && INALIENABLE_RIGHTS.includes(right),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
if (isInalienable) {
|
||||||
|
// If public dont throw and permit access
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
// Throw on a protected route
|
||||||
|
throw new Error('403.13 - Client certificate revoked')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Set context pubKey
|
// Set context pubKey
|
||||||
context.pubKey = Buffer.from(decoded.pubKey).toString('hex')
|
context.pubKey = Buffer.from(decoded.pubKey).toString('hex')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user