Skip to content

feat: support restricted properties for authorization #10793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/authorization/src/authorize-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,18 @@ export class AuthorizationInterceptor implements Provider<Interceptor> {
error.statusCode = this.options.defaultStatusCodeForDeny;
throw error;
}
return next();
const restrictedProperties: string[] = await invocationCtx.get(
AuthorizationTags.RESTRICTED_FIELDS,
);
const result = await next();
if (result && restrictedProperties) {
restrictedProperties.forEach(property => {
if (typeof result === 'object') {
delete (result as Record<string, unknown>)[property];
}
});
}
return result;
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/authorization/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export namespace AuthorizationTags {
* A tag for authorizers
*/
export const AUTHORIZER = 'authorizer';
/**
* A tag for restricted fields
*/
export const RESTRICTED_FIELDS = 'restricted.fields';
}
Loading