diff --git a/auth/rod.go b/auth/rod.go index 5168a4ff..0fd5f5a4 100644 --- a/auth/rod.go +++ b/auth/rod.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "time" "github.com/rusq/slackauth" "github.com/rusq/slackdump/v2/auth/auth_ui" @@ -31,7 +32,9 @@ func (p RodAuth) Type() Type { } type rodOpts struct { - ui browserAuthUIExt + ui browserAuthUIExt + autoTimeout time.Duration + useragent string } type browserAuthUIExt interface { @@ -81,16 +84,25 @@ func NewRODAuth(ctx context.Context, opts ...Option) (RodAuth, error) { return r, err } + cl, err := slackauth.New( + r.opts.workspace, + slackauth.WithChallengeFunc(r.opts.ui.ConfirmationCode), + ) + if err != nil { + return r, err + } + defer cl.Close() + var sp simpleProvider switch resp { case auth_ui.LInteractive: var err error - sp.Token, sp.Cookie, err = slackauth.Browser(ctx, r.opts.workspace, slackauth.WithUserAgentAuto()) + sp.Token, sp.Cookie, err = cl.Manual(ctx) if err != nil { return r, err } case auth_ui.LHeadless: - sp, err = headlessFlow(ctx, r.opts.workspace, r.opts.ui) + sp, err = headlessFlow(ctx, cl, r.opts.workspace, r.opts.ui) if err != nil { return r, err } @@ -105,7 +117,7 @@ func NewRODAuth(ctx context.Context, opts ...Option) (RodAuth, error) { }, nil } -func headlessFlow(ctx context.Context, workspace string, ui browserAuthUIExt) (sp simpleProvider, err error) { +func headlessFlow(ctx context.Context, cl *slackauth.Client, workspace string, ui browserAuthUIExt) (sp simpleProvider, err error) { username, password, err := ui.RequestCreds(os.Stdout, workspace) if err != nil { return sp, err @@ -116,17 +128,9 @@ func headlessFlow(ctx context.Context, workspace string, ui browserAuthUIExt) (s if password == "" { return sp, fmt.Errorf("password cannot be empty") } - fmt.Println("Logging in to Slack, depending on your connection speed, it will take 15-30 seconds...") - + fmt.Println("Logging in to Slack, depending on your connection speed, it will take 25-40 seconds...") var loginErr error - sp.Token, sp.Cookie, loginErr = slackauth.Headless( - ctx, - workspace, - username, - password, - slackauth.WithChallengeFunc(ui.ConfirmationCode), - slackauth.WithUserAgentAuto(), - ) + sp.Token, sp.Cookie, loginErr = cl.Headless(ctx, username, password) if loginErr != nil { return sp, loginErr } diff --git a/go.mod b/go.mod index 1a66f8c6..50920c0a 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/rusq/dlog v1.4.0 github.com/rusq/osenv/v2 v2.0.1 github.com/rusq/secure v0.0.4 - github.com/rusq/slackauth v0.2.1-0.20241005233803-21a386ee85da + github.com/rusq/slackauth v0.3.1 github.com/rusq/tracer v1.0.1 github.com/schollz/progressbar/v3 v3.13.0 github.com/slack-go/slack v0.12.5 diff --git a/go.sum b/go.sum index daa9886d..8343a606 100644 --- a/go.sum +++ b/go.sum @@ -125,6 +125,10 @@ github.com/rusq/slackauth v0.2.0 h1:efSwicJA/z9NS4wJFQg84vxlryFBCRODG2UPo9LfnUE= github.com/rusq/slackauth v0.2.0/go.mod h1:/+6JZULYSpWk7/Dc232132wF6UbFOLV8DhSz55zBcnw= github.com/rusq/slackauth v0.2.1-0.20241005233803-21a386ee85da h1:Rndrtq+DZyXVKPZ5TgZMDdZ1l2YUBENawnoQXxHgJLs= github.com/rusq/slackauth v0.2.1-0.20241005233803-21a386ee85da/go.mod h1:/+6JZULYSpWk7/Dc232132wF6UbFOLV8DhSz55zBcnw= +github.com/rusq/slackauth v0.3.0 h1:5ieWjlQHhmqMO4qhTsVZzXEsIt8AD6ADc2hhaxwERmY= +github.com/rusq/slackauth v0.3.0/go.mod h1:/+6JZULYSpWk7/Dc232132wF6UbFOLV8DhSz55zBcnw= +github.com/rusq/slackauth v0.3.1 h1:lAFuMQMVfe2VGZVCd8Hrwhqfrd8cy6nOzG0mhX9BvSg= +github.com/rusq/slackauth v0.3.1/go.mod h1:/+6JZULYSpWk7/Dc232132wF6UbFOLV8DhSz55zBcnw= github.com/rusq/tracer v1.0.1 h1:5u4PCV8NGO97VuAINQA4gOVRkPoqHimLE2jpezRVNMU= github.com/rusq/tracer v1.0.1/go.mod h1:Rqu48C3/K8bA5NPmF20Hft73v431MQIdM+Co+113pME= github.com/schollz/progressbar/v3 v3.13.0 h1:9TeeWRcjW2qd05I8Kf9knPkW4vLM/hYoa6z9ABvxje8=