mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 20:50:00 +00:00
TUN-6459: Add cloudflared user-agent to access calls
This commit is contained in:
@@ -29,6 +29,10 @@ const (
|
||||
AccessLoginWorkerPath = "/cdn-cgi/access/login"
|
||||
)
|
||||
|
||||
var (
|
||||
userAgent = "DEV"
|
||||
)
|
||||
|
||||
type AppInfo struct {
|
||||
AuthDomain string
|
||||
AppAUD string
|
||||
@@ -144,6 +148,10 @@ func isTokenLocked(lockFilePath string) bool {
|
||||
return exists && err == nil
|
||||
}
|
||||
|
||||
func Init(version string) {
|
||||
userAgent = fmt.Sprintf("cloudflared/%s", version)
|
||||
}
|
||||
|
||||
// FetchTokenWithRedirect will either load a stored token or generate a new one
|
||||
// it appends the full url as the redirect URL to the access cli request if opening the browser
|
||||
func FetchTokenWithRedirect(appURL *url.URL, appInfo *AppInfo, log *zerolog.Logger) (string, error) {
|
||||
@@ -261,6 +269,7 @@ func GetAppInfo(reqURL *url.URL) (*AppInfo, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create app info request")
|
||||
}
|
||||
appInfoReq.Header.Add("User-Agent", userAgent)
|
||||
resp, err := client.Do(appInfoReq)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get app info")
|
||||
@@ -311,6 +320,7 @@ func exchangeOrgToken(appURL *url.URL, orgToken string) (string, error) {
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to create app token request")
|
||||
}
|
||||
appTokenRequest.Header.Add("User-Agent", userAgent)
|
||||
resp, err := client.Do(appTokenRequest)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to get app token")
|
||||
|
Reference in New Issue
Block a user