-
Notifications
You must be signed in to change notification settings - Fork 937
feat: add enhanced support for Slack OAuth #10151
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ func TestRefreshToken(t *testing.T) { | |
return nil, xerrors.New("should not be called") | ||
}), | ||
}, | ||
GitConfigOpt: func(cfg *externalauth.Config) { | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
cfg.NoRefresh = true | ||
}, | ||
}) | ||
|
@@ -74,7 +74,7 @@ func TestRefreshToken(t *testing.T) { | |
return jwt.MapClaims{}, nil | ||
}), | ||
}, | ||
GitConfigOpt: func(cfg *externalauth.Config) { | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
cfg.NoRefresh = true | ||
}, | ||
}) | ||
|
@@ -117,7 +117,7 @@ func TestRefreshToken(t *testing.T) { | |
return jwt.MapClaims{}, xerrors.New(staticError) | ||
}), | ||
}, | ||
GitConfigOpt: func(cfg *externalauth.Config) { | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
}, | ||
}) | ||
|
||
|
@@ -142,7 +142,7 @@ func TestRefreshToken(t *testing.T) { | |
return jwt.MapClaims{}, oidctest.StatusError(http.StatusUnauthorized, xerrors.New(staticError)) | ||
}), | ||
}, | ||
GitConfigOpt: func(cfg *externalauth.Config) { | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
}, | ||
}) | ||
|
||
|
@@ -175,7 +175,7 @@ func TestRefreshToken(t *testing.T) { | |
return jwt.MapClaims{}, oidctest.StatusError(http.StatusUnauthorized, xerrors.New(staticError)) | ||
}), | ||
}, | ||
GitConfigOpt: func(cfg *externalauth.Config) { | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
cfg.Type = codersdk.EnhancedExternalAuthProviderGitHub.String() | ||
}, | ||
}) | ||
|
@@ -205,7 +205,7 @@ func TestRefreshToken(t *testing.T) { | |
return jwt.MapClaims{}, nil | ||
}), | ||
}, | ||
GitConfigOpt: func(cfg *externalauth.Config) { | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
cfg.Type = codersdk.EnhancedExternalAuthProviderGitHub.String() | ||
}, | ||
}) | ||
|
@@ -236,7 +236,7 @@ func TestRefreshToken(t *testing.T) { | |
return jwt.MapClaims{}, nil | ||
}), | ||
}, | ||
GitConfigOpt: func(cfg *externalauth.Config) { | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
cfg.Type = codersdk.EnhancedExternalAuthProviderGitHub.String() | ||
}, | ||
DB: db, | ||
|
@@ -260,6 +260,38 @@ func TestRefreshToken(t *testing.T) { | |
require.NoError(t, err) | ||
require.Equal(t, updated.OAuthAccessToken, dbLink.OAuthAccessToken, "token is updated in the DB") | ||
}) | ||
|
||
t.Run("SlackUserToken", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
db := dbfake.New() | ||
fake, config, link := setupOauth2Test(t, testConfig{ | ||
FakeIDPOpts: []oidctest.FakeIDPOpt{ | ||
oidctest.WithExtra(func(email string) map[string]interface{} { | ||
return map[string]interface{}{ | ||
"authed_user": map[string]interface{}{ | ||
"access_token": "slack-user-token", | ||
}, | ||
} | ||
}), | ||
Comment on lines
+270
to
+276
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add the existing fields to the params of I ask because it would be ideal to pass the actual access token: oidctest.WithExtra(func(email string, token map[string]interface{}) {
token["authed_user"] = map[string]interface{}{
"access_token": token["access_token"],
}
// Completely nuke the original access token?
token["access_token"] = "bogus_unused_token"
}), This would make it valid to the fake OIDC IDP. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was primarily trying to mimic the usage on the output side, which has the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is the But the access-token is invalidly set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}, | ||
ExternalAuthOpt: func(cfg *externalauth.Config) { | ||
cfg.Type = codersdk.EnhancedExternalAuthProviderSlack.String() | ||
cfg.SlackAuthedUserToken = true | ||
cfg.ValidateURL = "" | ||
}, | ||
DB: db, | ||
}) | ||
|
||
ctx := oidc.ClientContext(context.Background(), fake.HTTPClient(nil)) | ||
// Force a refresh | ||
link.OAuthExpiry = expired | ||
|
||
updated, ok, err := config.RefreshToken(ctx, db, link) | ||
require.NoError(t, err) | ||
require.True(t, ok) | ||
require.Equal(t, "slack-user-token", updated.OAuthAccessToken) | ||
}) | ||
} | ||
|
||
func TestConvertYAML(t *testing.T) { | ||
|
@@ -344,7 +376,7 @@ func TestConvertYAML(t *testing.T) { | |
type testConfig struct { | ||
FakeIDPOpts []oidctest.FakeIDPOpt | ||
CoderOIDCConfigOpts []func(cfg *coderd.OIDCConfig) | ||
GitConfigOpt func(cfg *externalauth.Config) | ||
ExternalAuthOpt func(cfg *externalauth.Config) | ||
// If DB is passed in, the link will be inserted into the DB. | ||
DB database.Store | ||
} | ||
|
@@ -367,7 +399,7 @@ func setupOauth2Test(t *testing.T, settings testConfig) (*oidctest.FakeIDP, *ext | |
ID: providerID, | ||
ValidateURL: fake.WellknownConfig().UserInfoURL, | ||
} | ||
settings.GitConfigOpt(config) | ||
settings.ExternalAuthOpt(config) | ||
|
||
oauthToken, err := fake.GenerateAuthenticatedToken(jwt.MapClaims{ | ||
"email": "test@coder.com", | ||
|
Uh oh!
There was an error while loading. Please reload this page.