File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
packages/keto-client-wrapper/src/lib Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
11
11
Type ,
12
12
} from '@nestjs/common' ;
13
13
import { Reflector } from '@nestjs/core' ;
14
+ import { PermissionApiExpandPermissionsRequest } from '@ory/client' ;
14
15
import type { Observable } from 'rxjs' ;
15
16
16
17
import {
@@ -91,8 +92,26 @@ export const OryAuthorizationGuard = (
91
92
}
92
93
93
94
try {
94
- const { data } = await this . oryService . checkPermission ( result . value ) ;
95
- return { allowed : data . allowed , relationTuple } ;
95
+ if ( result . value . subjectId || result . value . subjectSetNamespace ) {
96
+ const { data } = await this . oryService . checkPermission (
97
+ result . value
98
+ ) ;
99
+ return { allowed : data . allowed , relationTuple } ;
100
+ }
101
+ /**
102
+ * !experimental and counter-inituitive: to use with care
103
+ * We check that this resolves to no children, meaning that the object has no relations with any subject => it is public
104
+ */
105
+ const { data } = await this . oryService . expandPermissions (
106
+ result . value as PermissionApiExpandPermissionsRequest
107
+ ) ;
108
+ /**
109
+ * This Keto API endpoint has a quirk,it returns {code: 404, ... } when relation is not found
110
+ * ? maybe the check should be more complex based on data.type or data.children[n].type
111
+ **/
112
+ //
113
+ const allowed = ! data . children || data . children . length === 0 ;
114
+ return { allowed, relationTuple } ;
96
115
} catch ( error ) {
97
116
throw unauthorizedFactory . bind ( this ) ( context , error ) ;
98
117
}
You can’t perform that action at this time.
0 commit comments