From 824d8d2434d165e396f4a0904bfae1474d57cb93 Mon Sep 17 00:00:00 2001 From: Alec Fong Date: Wed, 13 Nov 2024 21:02:40 +0000 Subject: [PATCH] more explo --- pkg/auth/auth.go | 19 +++++++++++++++++++ pkg/auth/kas.go | 10 ++++++++++ pkg/cmd/cmd.go | 16 +++++----------- 3 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 pkg/auth/kas.go diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index c53f49af..7dcf0527 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -15,6 +15,25 @@ import ( "github.com/pkg/browser" ) +type AuthChecker interface { + GetCredentialProvider() entity.CredentialProvider +} + +func GetAuthenticator(ac AuthChecker) OAuth { + switch ac.GetCredentialProvider() { + case entity.CredentialProviderKAS: + return KasAuthenticator{} + case entity.CredentialProviderAuth0: + return Auth0Authenticator{ + Audience: "https://brevdev.us.auth0.com/api/v2/", + ClientID: "JaqJRLEsdat5w7Tb0WqmTxzIeqwqepmk", + DeviceCodeEndpoint: "https://brevdev.us.auth0.com/oauth/device/code", + OauthTokenEndpoint: "https://brevdev.us.auth0.com/oauth/token", + } + } + return nil +} + type LoginAuth struct { Auth } diff --git a/pkg/auth/kas.go b/pkg/auth/kas.go new file mode 100644 index 00000000..82b45ff3 --- /dev/null +++ b/pkg/auth/kas.go @@ -0,0 +1,10 @@ +package auth + +var _ OAuth = KasAuthenticator{} + +type KasAuthenticator struct { + Audience string + ClientID string + DeviceCodeEndpoint string + OauthTokenEndpoint string +} diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 498b9e24..4a0c7397 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -74,21 +74,15 @@ func NewBrevCommand() *cobra.Command { //nolint:funlen,gocognit,gocyclo // defin conf := config.NewConstants() fs := files.AppFs - // TODO: this is inappropriately tightly bound to auth0, we should bifurcate our path near here. - // auth.Multi.. auth.Dynamic.. ? - var authenticator auth.OAuth = auth.Auth0Authenticator{ - Audience: "https://brevdev.us.auth0.com/api/v2/", - ClientID: "JaqJRLEsdat5w7Tb0WqmTxzIeqwqepmk", - DeviceCodeEndpoint: "https://brevdev.us.auth0.com/oauth/device/code", - OauthTokenEndpoint: "https://brevdev.us.auth0.com/oauth/token", - } + fsStore := store. + NewBasicStore(). + WithFileSystem(fs) + + authenticator := auth.GetAuthenticator(nil) // todo // super annoying. this is needed to make the import stay _ = color.New(color.FgYellow, color.Bold).SprintFunc() - fsStore := store. - NewBasicStore(). - WithFileSystem(fs) loginAuth := auth.NewLoginAuth(fsStore, authenticator) noLoginAuth := auth.NewNoLoginAuth(fsStore, authenticator)