-
Notifications
You must be signed in to change notification settings - Fork 875
chore: add api endpoints to get idp field values #16063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, some minor tweaks
codersdk/idpsync.go
Outdated
@@ -163,3 +163,31 @@ func (c *Client) GetOrganizationAvailableIDPSyncFields(ctx context.Context, orgI | |||
var resp []string | |||
return resp, json.NewDecoder(res.Body).Decode(&resp) | |||
} | |||
|
|||
func (c *Client) GetIDPSyncFieldValues(ctx context.Context, claimField string) ([]string, error) { | |||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/settings/idpsync/field-values?claimField=%s", claimField), nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
claimField=%s
will not url encode special characters.
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/settings/idpsync/field-values?claimField=%s", claimField), nil) | |
qv := url.Values{} | |
qv.Add("claimField", claimField) | |
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/settings/idpsync/field-values?%s", qv.Encode()), nil) |
Example: https://go.dev/play/p/zN-CJsgWkz0
enterprise/coderd/idpsync.go
Outdated
ctx := r.Context() | ||
|
||
fields, err := api.Database.OIDCClaimFieldValues(ctx, database.OIDCClaimFieldValuesParams{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do the claimField
parsing in here.
ctx := r.Context() | |
fields, err := api.Database.OIDCClaimFieldValues(ctx, database.OIDCClaimFieldValuesParams{ | |
ctx := r.Context() | |
claimField := r.URL.Query().Get("claimField") | |
fields, err := api.Database.OIDCClaimFieldValues(ctx, database.OIDCClaimFieldValuesParams{ |
Also you should defend against an empty string here.
if claimField == "" {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "claimField query parameter is required",
})
return
}
Supports coder/internal#210