meetnearme / api

1 stars 0 forks source link

Extract User Roles in Auth #128

Closed j4inam closed 4 days ago

j4inam commented 5 days ago

This PR implements extraction of Authorizations (Roles) for currently authenticated user and adds them to request context.

Roles can be accessed in handlers using the request context like: roleClaims := ctx.Value("roleClaims").([]helpers.RoleClaim)

Sample Role Claims object:

mockRoleClaims := []helpers.RoleClaim{
        {
            Role:        "orgAdmin",
            ProjectID:   "project-id",
            ProjectName: "myapp.zitadel.cloud",
        },
        {
            Role:        "superAdmin",
            ProjectID:   "project-id",
            ProjectName: "myapp.zitadel.cloud",
        },
        {
            Role:        "sysAdmin",
            ProjectID:   "project-id",
            ProjectName: "myapp.zitadel.cloud",
        },
    }

Users can be assigned or revoked off of Authorizations using Zitadel Console or Using Zitadel Management APIs as shown in this video:

The roles being displayed on profile page is just to show an example of how to access the roles from request context. We can remove that later.

https://github.com/user-attachments/assets/69cf3b44-0736-452a-983c-3854ed9da859

brianfeister commented 5 days ago

@j4inam YES! 🚀 Can you fix this test and then we can merge?

--- FAIL: TestGetProfilePage (0.00s)
panic: interface conversion: interface {} is nil, not []helpers.RoleClaim [recovered]
    panic: interface conversion: interface {} is nil, not []helpers.RoleClaim