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

chore: update oauth token endpoint usage #83

Merged
merged 1 commit into from
Aug 9, 2023
Merged
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
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