-
Notifications
You must be signed in to change notification settings - Fork 46
Adding in Authorization Access Evaluation endpoint #1473
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
base: ENT-4372-Internal-ID
Are you sure you want to change the base?
Adding in Authorization Access Evaluation endpoint #1473
Conversation
|
@greptile review this pr plz |
Greptile OverviewGreptile SummaryThis PR implements the Key Changes:
Issue Found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant SDK as WorkOS SDK
participant Serializer
participant API as WorkOS API
Client->>SDK: check(options)
SDK->>Serializer: serializeAuthorizationCheckOptions(options)
Note over Serializer: Convert camelCase to snake_case<br/>Include only provided resource fields
Serializer-->>SDK: serialized payload
SDK->>API: POST /authorization/organization_memberships/{om_id}/check
API-->>SDK: { authorized: boolean }
SDK-->>Client: AuthorizationCheckResult
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 files reviewed, 1 comment
| describe('check', () => { | ||
| it('returns authorized when permission is granted (by resource ID)', async () => { | ||
| fetchOnce({ authorized: true }, { status: 200 }); | ||
|
|
||
| const result = await workos.authorization.check({ | ||
| organizationMembershipId: testOrgMembershipId, | ||
| permissionSlug: 'documents:edit', | ||
| resourceId: testResourceId, | ||
| }); | ||
|
|
||
| expect(fetchURL()).toContain( | ||
| `/authorization/organization_memberships/${testOrgMembershipId}/check`, | ||
| ); | ||
| expect(fetchBody()).toEqual({ | ||
| permission_slug: 'documents:edit', | ||
| resource_id: testResourceId, | ||
| }); | ||
| expect(result).toEqual({ authorized: true }); | ||
| }); | ||
|
|
||
| it('returns unauthorized when permission is not granted', async () => { | ||
| fetchOnce({ authorized: false }, { status: 200 }); | ||
|
|
||
| const result = await workos.authorization.check({ | ||
| organizationMembershipId: testOrgMembershipId, | ||
| permissionSlug: 'documents:delete', | ||
| resourceId: testResourceId, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ authorized: false }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding test cases for resourceExternalId + resourceTypeSlug and resourceTypeSlug alone to validate all resource identification methods
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 files reviewed, 1 comment
| export * from './authorization-resource.serializer'; | ||
| export * from './create-authorization-resource-options.serializer'; | ||
| export * from './update-authorization-resource-options.serializer'; | ||
| export * from './authorization-check-options.serializer'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon (all other exports have semicolons)
| export * from './authorization-check-options.serializer'; | |
| export * from './authorization-check-options.serializer'; |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
linear: https://linear.app/workos/issue/ENT-4372/sdk-updates
I decided to break up the work for ENT-4372 into a smaller pr's that we can be easily reviewed and merge them into ENT-4372-base-authorization-branch. Then we can have one final merge that merges ENT-4372-base-authorization-branch into the main.
desc: the goal of this pr is to implement the following endpoints in the node sdk.
check() | POST /authorization/organization_memberships/{om_id}/check
check() ~ https://github.com/workos/workos/blob/44963176350da59515a31bfeb5f5355b153d18e9/packages/api/src/authorization/authorization.controller.ts#L94