mirror of
https://fast.feibisi.com/https://github.com/parcelvoy/platform.git
synced 2025-09-04 12:56:14 +08:00
check revoked table for token
This commit is contained in:
parent
faf58bf2e6
commit
dffe680e04
2 changed files with 10 additions and 2 deletions
|
@ -6,7 +6,7 @@ import Project from '../projects/Project'
|
|||
import { ProjectApiKey } from '../projects/ProjectApiKey'
|
||||
import { getProjectApiKey } from '../projects/ProjectService'
|
||||
import AuthError from './AuthError'
|
||||
import { OAuthResponse } from './TokenRepository'
|
||||
import { isAccessTokenRevoked, OAuthResponse } from './TokenRepository'
|
||||
|
||||
export interface JwtAdmin {
|
||||
id: number
|
||||
|
@ -46,10 +46,14 @@ const parseAuth = async (ctx: Context) => {
|
|||
key: await getProjectApiKey(token),
|
||||
}
|
||||
} else {
|
||||
const admin = await verify(token) as JwtAdmin
|
||||
if (await isAccessTokenRevoked(token)) {
|
||||
throw new RequestError(AuthError.AccessDenied)
|
||||
}
|
||||
// user jwt
|
||||
return {
|
||||
scope: 'admin',
|
||||
admin: await verify(token) as JwtAdmin,
|
||||
admin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,10 @@ export interface OAuthResponse {
|
|||
expires_at: Date
|
||||
}
|
||||
|
||||
export async function isAccessTokenRevoked(token: string) {
|
||||
return (await RevokedAccessToken.count(qb => qb.where({ token }))) === 0
|
||||
}
|
||||
|
||||
export async function revokeAccessToken(token: string, expires_at: Date) {
|
||||
await RevokedAccessToken.insert({ token, expires_at })
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue