Skip to content

Commit

Permalink
feat: Add active organization's permission in session claims
Browse files Browse the repository at this point in the history
When decoding and verifying a session token, we are now parsing any organization
permissions that might be included and make them available as part of the
SessionClaims struct
  • Loading branch information
chanioxaris committed Nov 17, 2023
1 parent 714a002 commit 6ac8d1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions clerk/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ type TokenClaims struct {

type SessionClaims struct {
jwt.Claims
SessionID string `json:"sid"`
AuthorizedParty string `json:"azp"`
ActiveOrganizationID string `json:"org_id"`
ActiveOrganizationSlug string `json:"org_slug"`
ActiveOrganizationRole string `json:"org_role"`
Actor json.RawMessage `json:"act,omitempty"`
SessionID string `json:"sid"`
AuthorizedParty string `json:"azp"`
ActiveOrganizationID string `json:"org_id"`
ActiveOrganizationSlug string `json:"org_slug"`
ActiveOrganizationRole string `json:"org_role"`
ActiveOrganizationPermissions []string `json:"org_permissions"`
Actor json.RawMessage `json:"act,omitempty"`
}

// DecodeToken decodes a jwt token without verifying it.
Expand Down
11 changes: 6 additions & 5 deletions clerk/tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ var (
Expiry: nil,
IssuedAt: nil,
},
SessionID: "session_id",
AuthorizedParty: "authorized_party",
ActiveOrganizationID: "org_id",
ActiveOrganizationSlug: "org_slug",
ActiveOrganizationRole: "org_role",
SessionID: "session_id",
AuthorizedParty: "authorized_party",
ActiveOrganizationID: "org_id",
ActiveOrganizationSlug: "org_slug",
ActiveOrganizationRole: "org_role",
ActiveOrganizationPermissions: []string{"org:billing:manage", "org:report:view"},
}
)

Expand Down

0 comments on commit 6ac8d1b

Please sign in to comment.