-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: Custom User-Agent strings #221
Conversation
Added a new configuration option for our Backend so that users can specify a suffix for the User-Agent string that's included in every request headers.
@@ -219,7 +224,11 @@ func (b *defaultBackend) newRequest(ctx context.Context, apiReq *APIRequest) (*h | |||
} | |||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", secretKey)) | |||
req.Header.Add("Content-Type", "application/json") | |||
req.Header.Add("User-Agent", fmt.Sprintf("Clerk/%s SDK-Go/%s", clerkAPIVersion, sdkVersion)) | |||
userAgent := fmt.Sprintf("Clerk/%s SDK-Go/%s", clerkAPIVersion, sdkVersion) |
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 mentioning that Cloudflare analytics group by user agent, but I guess we can always filter by prefix!
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.
Thanks, I didn't know that. Do you think it's better to drop this change.
An alternative solution would be to leave the User-Agent string as is and maybe send a custom header instead. Would that be better?
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.
@georgepsarakis Can't we just use the X-Clerk-SDK
header?
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.
The X-Clerk-SDK
is already used, but we could add another one for debugging purposes, or to uniquely identify a consumer, like one of our partners or us.
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.
Yep, what I had in mind was to let the user set the User-Agent to whatever, not just the suffix, and rely on the X-Clerk-SDK
for wherever we need to identify if it came from the SDK.
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.
I see. That could work. However, I think we should have control over the User-Agent header, since it's a "standard" header but be loose in what we accept for custom ones.
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.
I'm a bit skeptical of this capability in general. Feels a bit weird to want to hijack the user agent header of an SDK. Do we have any requests about this? If not, then I'd go for what you proposed here @gkats:
An alternative solution would be to leave the User-Agent string as is and maybe send a custom header instead.
i.e., let the user add whatever extra headers they want in their requests.
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.
@agis we are following this approach in for BAPI requests by setting the request user-agent to {packageName}@{packageVersion}
.
ref: https://github.com/clerk/javascript/blob/main/packages/backend/src/constants.ts#L4
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.
Here's an alternative, which uses a custom header. #252
Closing this PR in favor of a solution which adds a custom header. |
Added a new configuration option for our Backend so that users can specify a suffix for the User-Agent string that's included in every request headers.