Skip to content

Commit 0c3cd12

Browse files
authored
Return proper responses for SCIM-provisioned identities (#2474)
1 parent 8a4bdb5 commit 0c3cd12

File tree

4 files changed

+363
-13
lines changed

4 files changed

+363
-13
lines changed

github/github-accessors.go

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/scim.go

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type SCIMUserAttributes struct {
2929
ExternalID *string `json:"externalId,omitempty"` // (Optional.)
3030
Groups []string `json:"groups,omitempty"` // (Optional.)
3131
Active *bool `json:"active,omitempty"` // (Optional.)
32+
// Only populated as a result of calling ListSCIMProvisionedIdentitiesOptions or GetSCIMProvisioningInfoForUser:
33+
ID *string `json:"id,omitempty"`
34+
Meta *SCIMMeta `json:"meta,omitempty"`
3235
}
3336

3437
// SCIMUserName represents SCIM user information.
@@ -45,6 +48,23 @@ type SCIMUserEmail struct {
4548
Type *string `json:"type,omitempty"` // (Optional.)
4649
}
4750

51+
// SCIMMeta represents metadata about the SCIM resource.
52+
type SCIMMeta struct {
53+
ResourceType *string `json:"resourceType,omitempty"`
54+
Created *Timestamp `json:"created,omitempty"`
55+
LastModified *Timestamp `json:"lastModified,omitempty"`
56+
Location *string `json:"location,omitempty"`
57+
}
58+
59+
// SCIMProvisionedIdentities represents the result of calling ListSCIMProvisionedIdentities.
60+
type SCIMProvisionedIdentities struct {
61+
Schemas []string `json:"schemas,omitempty"`
62+
TotalResults *int `json:"totalResults,omitempty"`
63+
ItemsPerPage *int `json:"itemsPerPage,omitempty"`
64+
StartIndex *int `json:"startIndex,omitempty"`
65+
Resources []*SCIMUserAttributes `json:"Resources,omitempty"`
66+
}
67+
4868
// ListSCIMProvisionedIdentitiesOptions represents options for ListSCIMProvisionedIdentities.
4969
//
5070
// Github API docs: https://docs.github.com/en/rest/scim#list-scim-provisioned-identities--parameters
@@ -62,17 +82,25 @@ type ListSCIMProvisionedIdentitiesOptions struct {
6282
// ListSCIMProvisionedIdentities lists SCIM provisioned identities.
6383
//
6484
// GitHub API docs: https://docs.github.com/en/rest/scim#list-scim-provisioned-identities
65-
func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org string, opts *ListSCIMProvisionedIdentitiesOptions) (*Response, error) {
85+
func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org string, opts *ListSCIMProvisionedIdentitiesOptions) (*SCIMProvisionedIdentities, *Response, error) {
6686
u := fmt.Sprintf("scim/v2/organizations/%v/Users", org)
6787
u, err := addOptions(u, opts)
6888
if err != nil {
69-
return nil, err
89+
return nil, nil, err
7090
}
91+
7192
req, err := s.client.NewRequest("GET", u, nil)
7293
if err != nil {
73-
return nil, err
94+
return nil, nil, err
7495
}
75-
return s.client.Do(ctx, req, nil)
96+
97+
identities := new(SCIMProvisionedIdentities)
98+
resp, err := s.client.Do(ctx, req, identities)
99+
if err != nil {
100+
return nil, resp, err
101+
}
102+
103+
return identities, resp, nil
76104
}
77105

78106
// ProvisionAndInviteSCIMUser provisions organization membership for a user, and sends an activation email to the email address.
@@ -84,23 +112,32 @@ func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string
84112
if err != nil {
85113
return nil, err
86114
}
115+
87116
req, err := s.client.NewRequest("POST", u, nil)
88117
if err != nil {
89118
return nil, err
90119
}
120+
91121
return s.client.Do(ctx, req, nil)
92122
}
93123

94124
// GetSCIMProvisioningInfoForUser returns SCIM provisioning information for a user.
95125
//
96126
// GitHub API docs: https://docs.github.com/en/rest/scim#supported-scim-user-attributes
97-
func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, scimUserID string) (*Response, error) {
127+
func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, scimUserID string) (*SCIMUserAttributes, *Response, error) {
98128
u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
99129
req, err := s.client.NewRequest("GET", u, nil)
100130
if err != nil {
101-
return nil, err
131+
return nil, nil, err
102132
}
103-
return s.client.Do(ctx, req, nil)
133+
134+
user := new(SCIMUserAttributes)
135+
resp, err := s.client.Do(ctx, req, &user)
136+
if err != nil {
137+
return nil, resp, err
138+
}
139+
140+
return user, resp, nil
104141
}
105142

106143
// UpdateProvisionedOrgMembership updates a provisioned organization membership.
@@ -112,10 +149,12 @@ func (s *SCIMService) UpdateProvisionedOrgMembership(ctx context.Context, org, s
112149
if err != nil {
113150
return nil, err
114151
}
152+
115153
req, err := s.client.NewRequest("PUT", u, nil)
116154
if err != nil {
117155
return nil, err
118156
}
157+
119158
return s.client.Do(ctx, req, nil)
120159
}
121160

@@ -143,10 +182,12 @@ func (s *SCIMService) UpdateAttributeForSCIMUser(ctx context.Context, org, scimU
143182
if err != nil {
144183
return nil, err
145184
}
185+
146186
req, err := s.client.NewRequest("PATCH", u, nil)
147187
if err != nil {
148188
return nil, err
149189
}
190+
150191
return s.client.Do(ctx, req, nil)
151192
}
152193

@@ -159,5 +200,6 @@ func (s *SCIMService) DeleteSCIMUserFromOrg(ctx context.Context, org, scimUserID
159200
if err != nil {
160201
return nil, err
161202
}
203+
162204
return s.client.Do(ctx, req, nil)
163205
}

0 commit comments

Comments
 (0)