Skip to content

Commit a2ccfb0

Browse files
committed
feat: allow external services to be authable
1 parent 5596fb2 commit a2ccfb0

28 files changed

+193
-111
lines changed

cli/errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"net/http/httptest"
77
"os"
88

9+
"golang.org/x/xerrors"
10+
911
"github.com/coder/coder/v2/cli/clibase"
1012
"github.com/coder/coder/v2/codersdk"
11-
"golang.org/x/xerrors"
1213
)
1314

1415
func (RootCmd) errorExample() *clibase.Cmd {

cli/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func ReadGitAuthProvidersFromEnv(environ []string) ([]codersdk.GitAuthConfig, er
171171
provider.AppInstallURL = v.Value
172172
case "APP_INSTALLATIONS_URL":
173173
provider.AppInstallationsURL = v.Value
174+
case "DISPLAY_NAME":
175+
provider.DisplayName = v.Value
176+
case "DISPLAY_ICON":
177+
provider.DisplayIcon = v.Value
174178
}
175179
providers[providerNum] = provider
176180
}

coderd/apidoc/docs.go

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/externalauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (api *API) externalAuthByID(w http.ResponseWriter, r *http.Request) {
3333
Authenticated: false,
3434
Device: config.DeviceAuth != nil,
3535
AppInstallURL: config.AppInstallURL,
36-
Type: config.Type.Pretty(),
36+
DisplayName: config.DisplayName,
3737
AppInstallations: []codersdk.ExternalAuthAppInstallation{},
3838
}
3939

coderd/externalauth/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ type Config struct {
3737
Type codersdk.ExternalAuthProvider
3838
// DeviceAuth is set if the provider uses the device flow.
3939
DeviceAuth *DeviceAuth
40+
// DisplayName is the name of the provider to display to the user.
41+
DisplayName string
42+
// DisplayIcon is the path to an image that will be displayed to the user.
43+
DisplayIcon string
4044

4145
// NoRefresh stops Coder from using the refresh token
4246
// to renew the access token.
@@ -258,6 +262,8 @@ func ConvertConfig(entries []codersdk.GitAuthConfig, accessURL *url.URL) ([]*Con
258262
typ = codersdk.ExternalAuthProviderGitHub
259263
case codersdk.ExternalAuthProviderGitLab:
260264
typ = codersdk.ExternalAuthProviderGitLab
265+
case codersdk.ExternalAuthProviderOpenIDConnect:
266+
typ = codersdk.ExternalAuthProviderOpenIDConnect
261267
default:
262268
return nil, xerrors.Errorf("unknown git provider type: %q", entry.Type)
263269
}
@@ -332,6 +338,12 @@ func ConvertConfig(entries []codersdk.GitAuthConfig, accessURL *url.URL) ([]*Con
332338
ValidateURL: entry.ValidateURL,
333339
AppInstallationsURL: entry.AppInstallationsURL,
334340
AppInstallURL: entry.AppInstallURL,
341+
DisplayName: entry.DisplayName,
342+
DisplayIcon: entry.DisplayIcon,
343+
}
344+
345+
if cfg.DisplayName == "" {
346+
cfg.DisplayName = typ.Pretty()
335347
}
336348

337349
if entry.DeviceFlow {

coderd/templateversions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ func (api *API) templateVersionExternalAuth(rw http.ResponseWriter, r *http.Requ
320320
ID: config.ID,
321321
Type: config.Type,
322322
AuthenticateURL: redirectURL.String(),
323+
DisplayName: config.DisplayName,
324+
DisplayIcon: config.DisplayIcon,
323325
}
324326

325327
authLink, err := api.Database.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams{

codersdk/deployment.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ type GitAuthConfig struct {
336336
Scopes []string `json:"scopes"`
337337
DeviceFlow bool `json:"device_flow"`
338338
DeviceCodeURL string `json:"device_code_url"`
339+
DisplayName string `json:"display_name"`
340+
DisplayIcon string `json:"display_icon"`
339341
}
340342

341343
type ProvisionerConfig struct {

codersdk/externalauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type ExternalAuth struct {
1111
Authenticated bool `json:"authenticated"`
1212
Device bool `json:"device"`
13-
Type string `json:"type"`
13+
DisplayName string `json:"display_name"`
1414

1515
// User is the user that authenticated with the provider.
1616
User *ExternalAuthUser `json:"user"`

codersdk/templateversions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type TemplateVersion struct {
3636
type TemplateVersionExternalAuth struct {
3737
ID string `json:"id"`
3838
Type ExternalAuthProvider `json:"type"`
39+
DisplayName string `json:"display_name"`
40+
DisplayIcon string `json:"display_icon"`
3941
AuthenticateURL string `json:"authenticate_url"`
4042
Authenticated bool `json:"authenticated"`
4143
}

codersdk/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ const (
770770
ExternalAuthProviderGitHub ExternalAuthProvider = "github"
771771
ExternalAuthProviderGitLab ExternalAuthProvider = "gitlab"
772772
ExternalAuthProviderBitBucket ExternalAuthProvider = "bitbucket"
773-
ExternalAuthProviderOpenIDConnect ExternalAuthProvider = "openid-connect"
773+
ExternalAuthProviderOpenIDConnect ExternalAuthProvider = "oidc"
774774
)
775775

776776
type WorkspaceAgentLog struct {

docs/api/general.md

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/git.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

Lines changed: 23 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/templates.md

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)