X Tutup
Skip to content

Commit 15bfb54

Browse files
committed
split auth flow code into new internal package
1 parent ecd1b34 commit 15bfb54

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ endif
2222
GO_LDFLAGS := -X github.com/cli/cli/command.Version=$(GH_VERSION) $(GO_LDFLAGS)
2323
GO_LDFLAGS := -X github.com/cli/cli/command.BuildDate=$(BUILD_DATE) $(GO_LDFLAGS)
2424
ifdef GH_OAUTH_CLIENT_SECRET
25-
GO_LDFLAGS := -X github.com/cli/cli/internal/config.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(GO_LDFLAGS)
26-
GO_LDFLAGS := -X github.com/cli/cli/internal/config.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS)
25+
GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(GO_LDFLAGS)
26+
GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS)
2727
endif
2828

2929
bin/gh: $(BUILD_FILES)
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package config
1+
package authflow
22

33
import (
44
"bufio"
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/cli/cli/api"
1212
"github.com/cli/cli/auth"
13+
"github.com/cli/cli/internal/config"
1314
"github.com/cli/cli/pkg/browser"
1415
"github.com/cli/cli/utils"
1516
"github.com/mattn/go-colorable"
@@ -22,14 +23,9 @@ var (
2223
oauthClientSecret = "34ddeff2b558a23d38fba8a6de74f086ede1cc0b"
2324
)
2425

25-
// IsGitHubApp reports whether an OAuth app is "GitHub CLI" or "GitHub CLI (dev)"
26-
func IsGitHubApp(id string) bool {
27-
// this intentionally doesn't use `oauthClientID` because that is a variable
28-
// that can potentially be changed at build time via GH_OAUTH_CLIENT_ID
29-
return id == "178c6fc778ccc68e1d6a" || id == "4d747ba5675d5d66553f"
30-
}
31-
32-
func AuthFlowWithConfig(cfg Config, hostname, notice string, additionalScopes []string) (string, error) {
26+
func AuthFlowWithConfig(cfg config.Config, hostname, notice string, additionalScopes []string) (string, error) {
27+
// TODO this probably shouldn't live in this package. It should probably be in a new package that
28+
// depends on both iostreams and config.
3329
stderr := colorable.NewColorableStderr()
3430

3531
token, userLogin, err := authFlow(hostname, stderr, notice, additionalScopes)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package config
1+
package authflow
22

33
const oauthSuccessPage = `
44
<!doctype html>

pkg/cmd/auth/login/login.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/AlecAivazis/survey/v2"
1010
"github.com/MakeNowJust/heredoc"
1111
"github.com/cli/cli/api"
12+
"github.com/cli/cli/internal/authflow"
1213
"github.com/cli/cli/internal/config"
1314
"github.com/cli/cli/internal/ghinstance"
1415
"github.com/cli/cli/pkg/cmd/auth/client"
@@ -202,7 +203,7 @@ func loginRun(opts *LoginOptions) error {
202203
}
203204

204205
if authMode == 0 {
205-
_, err := config.AuthFlowWithConfig(cfg, hostname, "", []string{})
206+
_, err := authflow.AuthFlowWithConfig(cfg, hostname, "", []string{})
206207
if err != nil {
207208
return fmt.Errorf("failed to authenticate via web browser: %w", err)
208209
}

pkg/cmd/auth/refresh/refresh.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/AlecAivazis/survey/v2"
77
"github.com/MakeNowJust/heredoc"
8+
"github.com/cli/cli/internal/authflow"
89
"github.com/cli/cli/internal/config"
910
"github.com/cli/cli/pkg/cmdutil"
1011
"github.com/cli/cli/pkg/iostreams"
@@ -26,7 +27,7 @@ func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra.
2627
IO: f.IOStreams,
2728
Config: f.Config,
2829
AuthFlow: func(cfg config.Config, hostname string, scopes []string) error {
29-
_, err := config.AuthFlowWithConfig(cfg, hostname, "", scopes)
30+
_, err := authflow.AuthFlowWithConfig(cfg, hostname, "", scopes)
3031
return err
3132
},
3233
}

0 commit comments

Comments
 (0)
X Tutup