Skip to content

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

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

jaaydenh
Copy link
Contributor

@jaaydenh jaaydenh commented Jan 7, 2025

@jaaydenh jaaydenh marked this pull request as ready for review January 7, 2025 22:37
@jaaydenh jaaydenh requested a review from Emyrk January 7, 2025 22:37
Copy link
Member

@Emyrk Emyrk left a 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

@@ -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)
Copy link
Member

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.

Suggested change
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

Comment on lines 398 to 400
ctx := r.Context()

fields, err := api.Database.OIDCClaimFieldValues(ctx, database.OIDCClaimFieldValuesParams{
Copy link
Member

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.

Suggested change
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
}

@jaaydenh jaaydenh requested a review from Emyrk January 8, 2025 18:50
@jaaydenh jaaydenh merged commit 6ca1e59 into main Jan 8, 2025
32 checks passed
@jaaydenh jaaydenh deleted the jaaydenh/idp-field-values-api branch January 8, 2025 21:07
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants