45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
|
|
import * as plugins from '../plugins.js';
|
||
|
|
import type { OidcManager } from './classes.oidcmanager.js';
|
||
|
|
|
||
|
|
@plugins.smartdata.Manager()
|
||
|
|
export class OidcAuthorizationCode extends plugins.smartdata.SmartDataDbDoc<
|
||
|
|
OidcAuthorizationCode,
|
||
|
|
plugins.idpInterfaces.data.IAuthorizationCode,
|
||
|
|
OidcManager
|
||
|
|
> {
|
||
|
|
public static hashCode(codeArg: string) {
|
||
|
|
return plugins.smarthash.sha256FromStringSync(codeArg);
|
||
|
|
}
|
||
|
|
|
||
|
|
@plugins.smartdata.unI()
|
||
|
|
public id: string;
|
||
|
|
|
||
|
|
@plugins.smartdata.svDb()
|
||
|
|
public data: plugins.idpInterfaces.data.IAuthorizationCode['data'] = {
|
||
|
|
codeHash: '',
|
||
|
|
clientId: '',
|
||
|
|
userId: '',
|
||
|
|
scopes: [],
|
||
|
|
redirectUri: '',
|
||
|
|
codeChallenge: undefined,
|
||
|
|
codeChallengeMethod: undefined,
|
||
|
|
nonce: undefined,
|
||
|
|
expiresAt: 0,
|
||
|
|
issuedAt: 0,
|
||
|
|
used: false,
|
||
|
|
};
|
||
|
|
|
||
|
|
public isExpired() {
|
||
|
|
return this.data.expiresAt < Date.now();
|
||
|
|
}
|
||
|
|
|
||
|
|
public matchesCode(codeArg: string) {
|
||
|
|
return this.data.codeHash === OidcAuthorizationCode.hashCode(codeArg);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async markUsed() {
|
||
|
|
this.data.used = true;
|
||
|
|
await this.save();
|
||
|
|
}
|
||
|
|
}
|