// PollToken polls the server until an access token is granted or denied.
PollToken polls the server until an access token is granted or denied.
// PollToken polls the server until an access token is granted or denied .
func (c Config) PollToken(ctx context.Context, code *DeviceCode) (*Token, *atlas.Response, error) {
	timeNow := code.timeNow
	if timeNow == nil {
		timeNow = time.Now
	}
	timeSleep := code.timeSleep
	if timeSleep == nil {
		timeSleep = time.Sleep
	}
	checkInterval := time.Duration(code.Interval) * time.Second
	expiresAt := timeNow().Add(time.Duration(code.ExpiresIn) * time.Second)
	for {
		timeSleep(checkInterval)
		token, resp, err := c.GetToken(ctx, code.DeviceCode)
		var target *atlas.ErrorResponse
		if errors.As(err, &target) && target.ErrorCode == "DEVICE_AUTHORIZATION_PENDING" {
			continue
		}
		if err != nil {
			return nil, resp, err
		}
		if timeNow().After(expiresAt) {
			return nil, nil, ErrTimeout
		}
		return token, resp, nil
	}
}
func ( c Config ) PollToken ( ctx context . Context , code * DeviceCode ) ( * Token , * atlas . Response , error ) { timeNow := code . timeNow if timeNow == nil { timeNow = time . Now } timeSleep := code . timeSleep if timeSleep == nil { timeSleep = time . Sleep } checkInterval := time . Duration ( code . Interval ) * time . Second expiresAt := timeNow ( ) . Add ( time . Duration ( code . ExpiresIn ) * time . Second ) for { timeSleep ( checkInterval ) token , resp , err := c . GetToken ( ctx , code . DeviceCode ) var target * atlas . ErrorResponse if errors . As ( err , & target ) && target . ErrorCode == " " { continue } if err != nil { return nil , resp , err } if timeNow ( ) . After ( expiresAt ) { return nil , nil , ErrTimeout } return token , resp , nil } }
PollToken polls the server until an access token is granted or denied.
PollToken polls the server until an access token is granted or denied .