@@ -26,8 +26,7 @@ const (
2626 appClientID = "databricks-cli"
2727
2828 // appRedirectAddr is the default address for the OAuth2 callback server.
29- // Using ":0" tells the system to pick a random available port.
30- appRedirectAddr = "localhost:0"
29+ appRedirectAddr = "localhost:8020"
3130
3231 // listenerTimeout is the maximum amount of time to acquire listener on
3332 // appRedirectAddr.
@@ -58,11 +57,6 @@ type PersistentAuth struct {
5857 // ctx is the context to use for underlying operations. This is needed in
5958 // order to implement the oauth2.TokenSource interface.
6059 ctx context.Context
61- // redirectAddr is the redirect address for OAuth2 callbacks. The value is
62- // set to localhost:PORT by startListener which will dynamically assign a
63- // random port. If a value is already provided, it will be used instead
64- // (e.g. for testing).
65- redirectAddr string
6660}
6761
6862type PersistentAuthOption func (* PersistentAuth )
@@ -134,6 +128,9 @@ func NewPersistentAuth(ctx context.Context, opts ...PersistentAuthOption) (*Pers
134128 return nil , fmt .Errorf ("cache: %w" , err )
135129 }
136130 }
131+ if p .oAuthArgument == nil {
132+ return nil , errors .New ("missing OAuthArgument" )
133+ }
137134 if err := p .validateArg (); err != nil {
138135 return nil , err
139136 }
@@ -165,9 +162,7 @@ func (a *PersistentAuth) Token() (t *oauth2.Token, err error) {
165162 return nil , fmt .Errorf ("token refresh: %w" , err )
166163 }
167164 }
168-
169- // Do not include the refresh token for security reasons. Refresh tokens are
170- // long-lived credentials that we do not want to expose unnecessarily.
165+ // do not print refresh token to end-user
171166 t .RefreshToken = ""
172167 return t , nil
173168}
@@ -274,19 +269,12 @@ func (a *PersistentAuth) Challenge() error {
274269// startListener starts a listener on appRedirectAddr, retrying if the address
275270// is already in use.
276271func (a * PersistentAuth ) startListener (ctx context.Context ) error {
277- // Use the value of redirectURL if it is already set. This is only expected
278- // in tests to set a fixed redirect URL.
279- addr := a .redirectAddr
280- if addr == "" {
281- addr = appRedirectAddr
282- }
283-
284272 listener , err := retries .Poll (ctx , listenerTimeout ,
285273 func () (* net.Listener , * retries.Err ) {
286274 var lc net.ListenConfig
287- l , err := lc .Listen (ctx , "tcp" , addr )
275+ l , err := lc .Listen (ctx , "tcp" , appRedirectAddr )
288276 if err != nil {
289- logger .Debugf (ctx , "failed to listen on %s: %v, retrying" , addr , err )
277+ logger .Debugf (ctx , "failed to listen on %s: %v, retrying" , appRedirectAddr , err )
290278 return nil , retries .Continue (err )
291279 }
292280 return & l , nil
@@ -295,10 +283,6 @@ func (a *PersistentAuth) startListener(ctx context.Context) error {
295283 return fmt .Errorf ("listener: %w" , err )
296284 }
297285 a .ln = * listener
298-
299- // Get the actual address that was assigned (including the port).
300- a .redirectAddr = a .ln .Addr ().String ()
301- logger .Debugf (ctx , "OAuth callback server listening on %s" , a .redirectAddr )
302286 return nil
303287}
304288
@@ -312,9 +296,6 @@ func (a *PersistentAuth) Close() error {
312296// validateArg ensures that the OAuthArgument is either a WorkspaceOAuthArgument
313297// or an AccountOAuthArgument.
314298func (a * PersistentAuth ) validateArg () error {
315- if a .oAuthArgument == nil {
316- return errors .New ("missing OAuthArgument" )
317- }
318299 _ , isWorkspaceArg := a .oAuthArgument .(WorkspaceOAuthArgument )
319300 _ , isAccountArg := a .oAuthArgument .(AccountOAuthArgument )
320301 if ! isWorkspaceArg && ! isAccountArg {
@@ -350,7 +331,7 @@ func (a *PersistentAuth) oauth2Config() (*oauth2.Config, error) {
350331 TokenURL : endpoints .TokenEndpoint ,
351332 AuthStyle : oauth2 .AuthStyleInParams ,
352333 },
353- RedirectURL : fmt .Sprintf ("http://%s" , a . redirectAddr ),
334+ RedirectURL : fmt .Sprintf ("http://%s" , appRedirectAddr ),
354335 Scopes : scopes ,
355336 }, nil
356337}
0 commit comments