31 lines
820 B
TypeScript
31 lines
820 B
TypeScript
|
|
import * as plugins from '../plugins.js';
|
||
|
|
import type { OidcManager } from './classes.oidcmanager.js';
|
||
|
|
|
||
|
|
@plugins.smartdata.Manager()
|
||
|
|
export class OidcUserConsent extends plugins.smartdata.SmartDataDbDoc<
|
||
|
|
OidcUserConsent,
|
||
|
|
plugins.idpInterfaces.data.IUserConsent,
|
||
|
|
OidcManager
|
||
|
|
> {
|
||
|
|
@plugins.smartdata.unI()
|
||
|
|
public id: string;
|
||
|
|
|
||
|
|
@plugins.smartdata.svDb()
|
||
|
|
public data: plugins.idpInterfaces.data.IUserConsent['data'] = {
|
||
|
|
userId: '',
|
||
|
|
clientId: '',
|
||
|
|
scopes: [],
|
||
|
|
grantedAt: 0,
|
||
|
|
updatedAt: 0,
|
||
|
|
};
|
||
|
|
|
||
|
|
public async grantScopes(scopesArg: plugins.idpInterfaces.data.TOidcScope[]) {
|
||
|
|
this.data.scopes = [...new Set([...this.data.scopes, ...scopesArg])];
|
||
|
|
if (!this.data.grantedAt) {
|
||
|
|
this.data.grantedAt = Date.now();
|
||
|
|
}
|
||
|
|
this.data.updatedAt = Date.now();
|
||
|
|
await this.save();
|
||
|
|
}
|
||
|
|
}
|