revokeConsent method
Withdraws userId's consent for clientId on tenant, and ends every
grant it allowed.
Implementation
Future<void> revokeConsent(
String userId,
String clientId, {
required String tenant,
}) async {
final DVRecord? consent = await _consents.read(
_consentKey(tenant, userId, clientId),
);
if (consent != null && consent.values['revoked_at'] == null) {
await _consents.write(
<String, Object?>{...consent.values, 'revoked_at': _stamp(_now())},
base: consent,
actor: userId,
tenant: tenant,
);
}
final List<Map<String, Object?>> grants = await database.query(
'SELECT id FROM dv_oauth_grants WHERE user_id = ? AND client_id = ? '
'AND tenant = ?',
<Object?>[userId, clientId, tenant],
);
for (final Map<String, Object?> row in grants) {
await _revokeGrant('${row['id']}', 'consent withdrawn');
}
}