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
|
| 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.
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.
added in
| 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.
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!
d48a6f8
into
ENT-4372-base-authorization-branch
Adding these endpoints to the sdk #1471 ``` getResource() ~ GET /authorization/resources/{resource_id} createResource() ~ POST /authorization/resources updateResource() ~ PATCH /authorization/resources/{resource_id} deleteResource() ~ DELETE /authorization/resources/{resource_id} ``` #1473 ``` check() | POST /authorization/organization_memberships/{om_id}/check ``` #1472 ``` listResources() | GET /authorization/organizations/{org_id}/resources getResourceByExternalId() | GET /authorization/organizations/{org_id}/resources/{type}/{external_id} updateResourceByExternalId() | PATCH /authorization/organizations/{org_id}/resources/{type}/{external_id} deleteResourceByExternalId() | DELETE /authorization/organizations/{org_id}/resources/{type}/{external_id} ``` #1474 ``` listRoleAssignments() | GET /authorization/organization_memberships/{om_id}/role_assignments assignRole() | POST /authorization/organization_memberships/{om_id}/role_assignments removeRole() | DELETE /authorization/organization_memberships/{om_id}/role_assignments removeRoleAssignment() | DELETE /authorization/organization_memberships/{om_id}/role_assignments/{ra_id} ``` #1478 ``` listResourcesForMembership() | GET /authorization/organization_memberships/{om_id}/resources listMembershipsForResource() | GET /authorization/resources/{resource_id}/organization_memberships listMembershipsForResourceByExternalId() | GET /authorization/organizations/{org_id}/resources/{type}/{external_id}/organization_memberships ```
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