Skip to content

Commit 6111d53

Browse files
committed
feat: add endpoints to list all authed external apps
Also add support for unlinking on the coder side to allow reflow.
1 parent 0c28a0e commit 6111d53

File tree

18 files changed

+481
-18
lines changed

18 files changed

+481
-18
lines changed

coderd/apidoc/docs.go

Lines changed: 75 additions & 0 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: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,21 @@ func New(options *Options) *API {
660660
r.Get("/{fileID}", api.fileByID)
661661
r.Post("/", api.postFile)
662662
})
663-
r.Route("/external-auth/{externalauth}", func(r chi.Router) {
663+
r.Route("/external-auth", func(r chi.Router) {
664664
r.Use(
665665
apiKeyMiddleware,
666-
httpmw.ExtractExternalAuthParam(options.ExternalAuthConfigs),
667666
)
668-
r.Get("/", api.externalAuthByID)
669-
r.Post("/device", api.postExternalAuthDeviceByID)
670-
r.Get("/device", api.externalAuthDeviceByID)
667+
// Get without a specific external auth ID will return all external auths.
668+
r.Get("/", api.userExternalAuths)
669+
r.Route("/{externalauth}", func(r chi.Router) {
670+
r.Use(
671+
httpmw.ExtractExternalAuthParam(options.ExternalAuthConfigs),
672+
)
673+
r.Delete("/", api.deleteExternalAuthByID)
674+
r.Get("/", api.externalAuthByID)
675+
r.Post("/device", api.postExternalAuthDeviceByID)
676+
r.Get("/device", api.externalAuthDeviceByID)
677+
})
671678
})
672679
r.Route("/organizations", func(r chi.Router) {
673680
r.Use(
@@ -803,6 +810,9 @@ func New(options *Options) *API {
803810
// These roles apply to the site wide permissions.
804811
r.Put("/roles", api.putUserRoles)
805812
r.Get("/roles", api.userRoles)
813+
r.Route("/external-auths", func(r chi.Router) {
814+
r.Get("/", api.userExternalAuths)
815+
})
806816

807817
r.Route("/keys", func(r chi.Router) {
808818
r.Post("/", api.postAPIKey)

coderd/database/db2sdk/db2sdk.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ import (
1616
"github.com/coder/coder/v2/provisionersdk/proto"
1717
)
1818

19+
func ExternalAuths(auths []database.ExternalAuthLink) []codersdk.ExternalAuthLink {
20+
out := make([]codersdk.ExternalAuthLink, 0, len(auths))
21+
for _, auth := range auths {
22+
out = append(out, ExternalAuth(auth))
23+
}
24+
return out
25+
}
26+
27+
func ExternalAuth(auth database.ExternalAuthLink) codersdk.ExternalAuthLink {
28+
return codersdk.ExternalAuthLink{
29+
ProviderID: auth.ProviderID,
30+
CreatedAt: auth.CreatedAt,
31+
UpdatedAt: auth.UpdatedAt,
32+
HasRefreshToken: auth.OAuthRefreshToken != "",
33+
Expires: auth.OAuthExpiry,
34+
}
35+
}
36+
1937
func WorkspaceBuildParameters(params []database.WorkspaceBuildParameter) []codersdk.WorkspaceBuildParameter {
2038
out := make([]codersdk.WorkspaceBuildParameter, len(params))
2139
for i, p := range params {

coderd/database/dbauthz/dbauthz.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ func (q *querier) DeleteCoordinator(ctx context.Context, id uuid.UUID) error {
740740
return q.db.DeleteCoordinator(ctx, id)
741741
}
742742

743+
func (q *querier) DeleteExternalAuthLink(ctx context.Context, arg database.DeleteExternalAuthLinkParams) error {
744+
return deleteQ(q.log, q.auth, func(ctx context.Context, arg database.DeleteExternalAuthLinkParams) (database.ExternalAuthLink, error) {
745+
return q.db.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams{UserID: arg.UserID, ProviderID: arg.ProviderID})
746+
}, q.db.DeleteExternalAuthLink)(ctx, arg)
747+
}
748+
743749
func (q *querier) DeleteGitSSHKey(ctx context.Context, userID uuid.UUID) error {
744750
return deleteQ(q.log, q.auth, q.db.GetGitSSHKey, q.db.DeleteGitSSHKey)(ctx, userID)
745751
}

coderd/database/dbmem/dbmem.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,15 @@ func (*FakeQuerier) DeleteCoordinator(context.Context, uuid.UUID) error {
10191019
return ErrUnimplemented
10201020
}
10211021

1022+
func (q *FakeQuerier) DeleteExternalAuthLink(ctx context.Context, arg database.DeleteExternalAuthLinkParams) error {
1023+
err := validateDatabaseType(arg)
1024+
if err != nil {
1025+
return err
1026+
}
1027+
1028+
panic("not implemented")
1029+
}
1030+
10221031
func (q *FakeQuerier) DeleteGitSSHKey(_ context.Context, userID uuid.UUID) error {
10231032
q.mutex.Lock()
10241033
defer q.mutex.Unlock()

coderd/database/dbmetrics/dbmetrics.go

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

coderd/database/dbmock/dbmock.go

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

coderd/database/querier.go

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

coderd/database/queries.sql.go

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

coderd/database/queries/externalauth.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-- name: GetExternalAuthLink :one
22
SELECT * FROM external_auth_links WHERE provider_id = $1 AND user_id = $2;
33

4+
-- name: DeleteExternalAuthLink :exec
5+
DELETE FROM external_auth_links WHERE provider_id = $1 AND user_id = $2;
6+
47
-- name: GetExternalAuthLinksByUserID :many
58
SELECT * FROM external_auth_links WHERE user_id = $1;
69

0 commit comments

Comments
 (0)