Skip to content

Commit

Permalink
Merge pull request #330 from rusq/ua-fix-followup
Browse files Browse the repository at this point in the history
update the slackauth and relevant auth code
  • Loading branch information
rusq authored Oct 6, 2024
2 parents b70a532 + 1fe8697 commit 91b93e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
27 changes: 14 additions & 13 deletions auth/rod.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,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
}
Expand All @@ -105,7 +114,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
Expand All @@ -116,17 +125,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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 91b93e7

Please sign in to comment.