Skip to content

Commit

Permalink
feat: add roles and organiaztion-related data for userInfoResponse (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyijun authored Jan 10, 2024
1 parent d846372 commit 80445b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
6 changes: 5 additions & 1 deletion core/fetch_user_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func TestFetchUserInfo(t *testing.T) {
`"phone_number": "12345678",` +
`"phone_number_verified": true,` +
`"custom_data": {"level": 1},` +
`"identities": {"google": {"id": 1}}` +
`"identities": {"google": {"id": 1}},` +
`"roles": ["role1", "role2"],` +
`"organizations": ["org1"],` +
`"organization_roles": ["viewer", "editor"],` +
`"organization_data": [{"id": "org1", "name": "org1Name", "description": "org1Desc"}]` +
`}`

httpmock.RegisterResponder(
Expand Down
32 changes: 21 additions & 11 deletions core/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,27 @@ type Organization struct {
}

type UserInfoResponse struct {
Sub string `json:"sub"`
Name string `json:"name"`
Username string `json:"username"`
Picture string `json:"picture"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
PhoneNumber string `json:"phone_number"`
PhoneNumberVerified bool `json:"phone_number_verified"`
CustomData map[string]interface{} `json:"custom_data"`
Identities map[string]interface{} `json:"identities"`
OrganizationData []Organization `json:"organization_data"`
Sub string `json:"sub"` // The user's unique ID.
Name string `json:"name"` // The user's full name.
Username string `json:"username"` // The user's username.
Picture string `json:"picture"` // The user's profile picture URL.
Email string `json:"email"` // The user's email address.
EmailVerified bool `json:"email_verified"` // Whether the user's email address is verified.
PhoneNumber string `json:"phone_number"` // The user's phone number.
PhoneNumberVerified bool `json:"phone_number_verified"` // Whether the user's phone number is verified.
CustomData map[string]interface{} `json:"custom_data"` // The user's custom data
Identities map[string]interface{} `json:"identities"` // The user's social identities information
Roles []string `json:"roles"` // The role names of the current user.
Organizations []string `json:"organizations"` // The organization IDs that the user has membership.
// The organization roles that the user has.
// Each role is in the format of `<organization_id>:<role_name>`.
// # Example #
// The following array indicates that user is an admin of org1 and a member of org2:
// ```go
// {"org1:admin", "org2:member"}
// ```
OrganizationRoles []string `json:"organization_roles"`
OrganizationData []Organization `json:"organization_data"` // The organization data that the user has membership.
}

type IdTokenClaims struct {
Expand Down

0 comments on commit 80445b2

Please sign in to comment.