Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing auth redirect #731

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/snyk/snyk-ls

go 1.22
go 1.22.0

toolchain go1.22.6
toolchain go1.23.4

require (
github.com/adrg/strutil v0.3.1
Expand All @@ -27,8 +27,8 @@ require (
github.com/rs/zerolog v1.33.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/snyk/code-client-go v1.10.0
github.com/snyk/go-application-framework v0.0.0-20241009095349-dc0fb55f3eb3
github.com/snyk/code-client-go v1.11.1
github.com/snyk/go-application-framework v0.0.0-20241209184421-ca04d08658d4
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand All @@ -37,43 +37,43 @@ require (
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c
go.lsp.dev/uri v0.3.0
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/mod v0.20.0
golang.org/x/net v0.28.0
golang.org/x/oauth2 v0.22.0
golang.org/x/sync v0.8.0
golang.org/x/mod v0.22.0
golang.org/x/net v0.31.0
golang.org/x/oauth2 v0.23.0
golang.org/x/sync v0.9.0
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cuelabs.dev/go/oci/ociregistry v0.0.0-20240807094312-a32ad29eed79 // indirect
cuelang.org/go v0.10.0 // indirect
cuelabs.dev/go/oci/ociregistry v0.0.0-20240906074133-82eb438dd565 // indirect
cuelang.org/go v0.11.0 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/cloudflare/circl v1.3.8 // indirect
github.com/cloudflare/circl v1.5.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/creachadair/mds v0.16.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.5 // indirect
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deepmap/oapi-codegen v1.16.3 // indirect
github.com/emicklei/proto v1.13.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/getkin/kin-openapi v0.124.0 // indirect
github.com/getkin/kin-openapi v0.128.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-billy/v5 v5.6.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -98,21 +98,22 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.3.0 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pact-foundation/pact-go/v2 v2.0.5 // indirect
github.com/pact-foundation/pact-go/v2 v2.0.8 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 // indirect
github.com/protocolbuffers/txtpbfmt v0.0.0-20240823084532-8e6b51fa9bef // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.1-0.20240709150035-ccf4b4329d21 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/snyk/error-catalog-golang-public v0.0.0-20240809094525-c48d19c27edb // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/snyk/error-catalog-golang-public v0.0.0-20241030160523-0aa643bb7069 // indirect
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand All @@ -127,10 +128,10 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.27.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Expand Down
1 change: 1 addition & 0 deletions infrastructure/authentication/auth_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewOAuthProvider(
conf,
auth.WithOpenBrowserFunc(openBrowserFunc),
auth.WithTokenRefresherFunc(customTokenRefresherFunc),
auth.WithLogger(c.Logger()),
)
return newOAuthProvider(conf, authenticator, c.Logger())
}
11 changes: 10 additions & 1 deletion infrastructure/authentication/auth_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (a *AuthenticationServiceImpl) authenticate(ctx context.Context) (token str
prioritizedUrl := getPrioritizedApiUrl(customUrl, engineUrl)

if prioritizedUrl != customUrl {
defer a.notifier.SendShowMessage(sglsp.Info, "The Snyk API Endpoint has been updated.")
defer a.notifier.SendShowMessage(sglsp.Info, fmt.Sprintf("The Snyk API Endpoint has been updated to %s.", prioritizedUrl))
}

a.c.UpdateApiEndpoints(prioritizedUrl)
Expand Down Expand Up @@ -144,6 +144,12 @@ func getPrioritizedApiUrl(customUrl string, engineUrl string) string {
defaultUrl := config.DefaultSnykApiUrl
customUrl = strings.TrimRight(customUrl, "/ ")

//This case is for testing. In this case pre-prod is the default url, and we want to redirect calls to url
//provided by engine.
if customUrl == "https://api.pre-prod.snyk.io" && engineUrl != "" {
return engineUrl
}

// If the custom URL is not changed (equals default) and no engine URL is provided,
// use the default URL.
if customUrl == defaultUrl && engineUrl == "" {
Expand Down Expand Up @@ -222,6 +228,9 @@ func (a *AuthenticationServiceImpl) IsAuthenticated() bool {
func (a *AuthenticationServiceImpl) isAuthenticated() bool {
logger := a.c.Logger().With().Str("method", "AuthenticationService.IsAuthenticated").Logger()

engineUrl := a.c.Engine().GetConfiguration().GetString(configuration.API_URL)
a.notifier.SendShowMessage(sglsp.Info, fmt.Sprintf("EngineUrl is %s.", engineUrl))

_, found := a.authCache.Get(a.c.Token())
if found {
logger.Debug().Msg("IsAuthenticated (found in cache)")
Expand Down
Loading