Skip to content

Commit

Permalink
chore: prepare usage of snyk apps for oauth
Browse files Browse the repository at this point in the history
chore: update test

chore: update oauth configuration

fix: update oauth settings
  • Loading branch information
PeterSchafer committed Aug 8, 2023
1 parent 9308110 commit 465663c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions pkg/auth/oauth2authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

const (
CONFIG_KEY_OAUTH_TOKEN string = "INTERNAL_OAUTH_TOKEN_STORAGE"
OAUTH_CLIENT_ID string = "0oa37b7oa3zOoDWCe4h7"
OAUTH_CLIENT_ID string = "b56d4c2e-b9e1-4d27-8773-ad47eafb0956"
CALLBACK_HOSTNAME string = "127.0.0.1"
CALLBACK_PATH string = "/authorization-code/callback"
TIMEOUT_SECONDS time.Duration = 120 * time.Second
Expand Down Expand Up @@ -77,9 +77,9 @@ func getRedirectUri(port int) string {

func getOAuthConfiguration(config configuration.Configuration) *oauth2.Config {
appUrl := config.GetString(configuration.WEB_APP_URL)
//tokenUrl := strings.Replace(appUrl, "app.", "id.", 1) + "/oauth2/default/v1/token" // TODO HEAD-208
tokenUrl := "https://snyk-fedramp-alpha.okta.com/oauth2/default/v1/token" // TODO HEAD-208
authUrl := appUrl + "/oauth/authorize"
apiUrl := config.GetString(configuration.API_URL)
tokenUrl := apiUrl + "/oauth2/token"
authUrl := appUrl + "/oauth2/authorize"

conf := &oauth2.Config{
ClientID: OAUTH_CLIENT_ID,
Expand Down Expand Up @@ -236,9 +236,10 @@ func (o *oAuth2Authenticator) Authenticate() error {

url := o.oauthConfig.AuthCodeURL(state, oauth2.AccessTypeOffline,
oauth2.SetAuthURLParam("code_challenge", codeChallenge),
oauth2.SetAuthURLParam("code_challenge_method", "s256"),
oauth2.SetAuthURLParam("code_challenge_method", "S256"),
oauth2.SetAuthURLParam("response_type", "code"),
oauth2.SetAuthURLParam("scope", "offline_access"))
oauth2.SetAuthURLParam("scope", "offline_access"),
oauth2.SetAuthURLParam("version", "2021-08-11~experimental"))

// launch browser
go o.openBrowserFunc(url)
Expand Down
6 changes: 4 additions & 2 deletions pkg/auth/oauth2authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ func Test_getToken_BadToken_ReturnsError(t *testing.T) {

func Test_getOAuthConfiguration(t *testing.T) {
webapp := "https://app.fedramp-alpha.snykgov.io"
api := "https://api.fedramp-alpha.snykgov.io"

config := configuration.NewInMemory()
config.Set(configuration.WEB_APP_URL, webapp)
config.Set(configuration.API_URL, api)

oauthConfig := getOAuthConfiguration(config)

assert.Equal(t, "", oauthConfig.RedirectURL)
assert.Equal(t, OAUTH_CLIENT_ID, oauthConfig.ClientID)
assert.Equal(t, webapp+"/oauth/authorize", oauthConfig.Endpoint.AuthURL)
// assert.Equal(t, "https://id.fedramp-alpha.snykgov.io/oauth2/default/v1/token", oauthConfig.Endpoint.TokenURL)
assert.Equal(t, webapp+"/oauth2/authorize", oauthConfig.Endpoint.AuthURL)
assert.Equal(t, api+"/oauth2/token", oauthConfig.Endpoint.TokenURL)
}

func Test_AddAuthenticationHeader_validToken(t *testing.T) {
Expand Down

0 comments on commit 465663c

Please sign in to comment.