oak-general-business/es/components/oauth/records/index.js

70 lines
1.8 KiB
JavaScript

import assert from "assert";
import { generateNewId } from "oak-domain/lib/utils/uuid";
export default OakComponent({
entity: 'oauthUserAuthorization',
isList: true,
projection: {
userId: 1,
applicationId: 1,
authorizedAt: 1,
codeId: 1,
tokenId: 1,
usageState: 1,
$$createAt$$: 1,
application: {
logo: 1,
name: 1,
description: 1,
isConfidential: 1,
},
code: {
scope: 1,
},
token: {
accessExpiresAt: 1,
refreshExpiresAt: 1,
lastUsedAt: 1,
revokedAt: 1,
}
},
pagination: {
pageSize: 5,
currentPage: 1,
},
filters: [{
filter() {
const userId = this.features.token.getUserId();
const systemId = this.features.application.getApplication()?.systemId;
return {
userId,
application: {
systemId: systemId
},
usageState: {
$in: ['granted', 'denied', 'revoked']
}
};
},
}],
formData({ data }) {
return {
list: data,
};
},
properties: {},
methods: {
async revoke(item) {
assert(item.id, 'No id found for this authorization record');
await this.features.cache.operate("oauthUserAuthorization", {
action: "revoke",
id: generateNewId(),
data: {},
filter: {
id: item.id
}
});
console.log('Revoking authorization for:', item.id);
}
}
});