@@ -18,7 +18,6 @@ import (
18
18
"time"
19
19
20
20
"github.com/tailscale/hujson"
21
- "golang.org/x/oauth2/clientcredentials"
22
21
)
23
22
24
23
type (
@@ -29,13 +28,13 @@ type (
29
28
// UserAgent configures the User-Agent HTTP header for requests. Defaults to "tailscale-client-go".
30
29
UserAgent string
31
30
// APIKey allows specifying an APIKey to use for authentication.
31
+ // To use OAuth Client credentials, construct an [http.Client] using [OAuthConfig] and specify that below.
32
32
APIKey string
33
33
// Tailnet allows specifying a specific Tailnet by name, to which this Client will connect by default.
34
34
Tailnet string
35
35
36
36
// HTTP is the [http.Client] to use for requests to the API server.
37
37
// If not specified, a new [http.Client] with a Timeout of 1 minute will be used.
38
- // This will be ignored if using [Client].UseOAuth.
39
38
HTTP * http.Client
40
39
41
40
initOnce sync.Once
@@ -72,25 +71,17 @@ const defaultHttpClientTimeout = time.Minute
72
71
const defaultUserAgent = "tailscale-client-go"
73
72
74
73
var defaultBaseURL * url.URL
75
- var oauthRelTokenURL * url.URL
76
74
77
75
func init () {
78
76
var err error
79
77
defaultBaseURL , err = url .Parse ("https://api.tailscale.com" )
80
78
if err != nil {
81
79
panic (fmt .Errorf ("failed to parse defaultBaseURL: %w" , err ))
82
80
}
83
-
84
- oauthRelTokenURL , err = url .Parse ("/api/v2/oauth/token" )
85
- if err != nil {
86
- panic (fmt .Errorf ("failed to parse oauthRelTokenURL: %s" , err ))
87
- }
88
81
}
89
82
90
83
// init returns a new instance of the Client type that will perform operations against a chosen tailnet and will
91
84
// provide the apiKey for authorization.
92
- //
93
- // To use OAuth Client credentials, call [Client].UseOAuth.
94
85
func (c * Client ) init () {
95
86
c .initOnce .Do (func () {
96
87
if c .BaseURL == nil {
@@ -115,21 +106,6 @@ func (c *Client) init() {
115
106
})
116
107
}
117
108
118
- // UseOAuth configures the client to use the specified OAuth credentials.
119
- // If [Client].HTTP was previously specified, this replaces it.
120
- func (c * Client ) UseOAuth (clientID , clientSecret string , scopes []string ) {
121
- oauthConfig := clientcredentials.Config {
122
- ClientID : clientID ,
123
- ClientSecret : clientSecret ,
124
- TokenURL : c .BaseURL .ResolveReference (oauthRelTokenURL ).String (),
125
- Scopes : scopes ,
126
- }
127
-
128
- // use context.Background() here, since this is used to refresh the token in the future
129
- c .HTTP = oauthConfig .Client (context .Background ())
130
- c .HTTP .Timeout = defaultHttpClientTimeout
131
- }
132
-
133
109
// Contacts() provides access to https://tailscale.com/api#tag/contacts.
134
110
func (c * Client ) Contacts () * ContactsResource {
135
111
c .init ()
0 commit comments