Skip to content

feat: add OAuth2 applications #11197

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

Merged
merged 30 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c7d69e2
Add database tables for OAuth2 applications
code-asher Dec 11, 2023
3c096b2
Add endpoints for managing OAuth2 applications
code-asher Dec 11, 2023
430140e
Add frontend for managing OAuth2 applications
code-asher Dec 12, 2023
35978ed
Add types to oauth2 stories
code-asher Dec 14, 2023
7e2db88
Remove redundant existence checks
code-asher Dec 14, 2023
f224ebc
Remove unnecessary function wrappers
code-asher Dec 14, 2023
c57b400
Add types to default meta storybook exports
code-asher Dec 14, 2023
d2e6d37
Mark secrets array as readonly
code-asher Dec 14, 2023
de11363
Replace isUpdating with object
code-asher Dec 14, 2023
d767d25
Remove unnecessary undefined on useState
code-asher Dec 14, 2023
9473478
Rename apps to "provider apps"
code-asher Dec 14, 2023
70ffd00
Comment about hashed and display secret
code-asher Dec 14, 2023
8035333
Rename secret ID param
code-asher Dec 14, 2023
fd13c02
Move db to sdk conversions to db2sdk.go
code-asher Dec 14, 2023
64ef328
Be more helpful with app and secret mismatches
code-asher Dec 14, 2023
7c7fd7e
Clarify new secret vs secret list
code-asher Dec 14, 2023
765ee0c
Remove invalid JSON from test entities
code-asher Dec 14, 2023
1e08e4d
Remove redundant type
code-asher Dec 14, 2023
3e69495
Refactor mutations
code-asher Dec 15, 2023
41ff886
Merge remote-tracking branch 'github/main' into asher/oauth-provider
code-asher Dec 15, 2023
6e2ec5a
Bump migration number
code-asher Dec 15, 2023
7c3b1b1
make gen
code-asher Dec 15, 2023
7e7cda5
Add dev and entitlement checks to oauth2 provider
code-asher Dec 15, 2023
1be8f15
Move badges underneath header
code-asher Dec 18, 2023
511850b
Improve client ID markup
code-asher Dec 18, 2023
e8e8a94
Show a 404 page on /deployment/oauth2-provider/
code-asher Dec 18, 2023
c2934fb
Clear full new secret if deleted
code-asher Dec 18, 2023
b9a6765
Merge remote-tracking branch 'github/main' into asher/oauth-provider
code-asher Dec 18, 2023
d8927ca
Bump migration number
code-asher Dec 18, 2023
bd8cab4
Fix undefined error in edit oauth2 stories
code-asher Dec 21, 2023
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
Prev Previous commit
Next Next commit
Move db to sdk conversions to db2sdk.go
  • Loading branch information
code-asher committed Dec 14, 2023
commit fd13c0261b8cfb3eacb87b51ab6e7f5f3a9e9019
17 changes: 17 additions & 0 deletions coderd/database/db2sdk/db2sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,20 @@ func templateVersionParameterOptions(rawOptions json.RawMessage) ([]codersdk.Tem
}
return options, nil
}

func OAuth2ProviderApp(dbApp database.OAuth2ProviderApp) codersdk.OAuth2ProviderApp {
return codersdk.OAuth2ProviderApp{
ID: dbApp.ID,
Name: dbApp.Name,
CallbackURL: dbApp.CallbackURL,
Icon: dbApp.Icon,
}
}

func OAuth2ProviderApps(dbApps []database.OAuth2ProviderApp) []codersdk.OAuth2ProviderApp {
apps := []codersdk.OAuth2ProviderApp{}
for _, dbApp := range dbApps {
apps = append(apps, OAuth2ProviderApp(dbApp))
}
return apps
}
22 changes: 5 additions & 17 deletions enterprise/coderd/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ import (
"github.com/google/uuid"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/db2sdk"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/coderd/httpmw"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/cryptorand"
)

func convertApp(app database.OAuth2ProviderApp) codersdk.OAuth2ProviderApp {
return codersdk.OAuth2ProviderApp{
ID: app.ID,
Name: app.Name,
CallbackURL: app.CallbackURL,
Icon: app.Icon,
}
}

// @Summary Get OAuth2 applications.
// @ID get-oauth2-applications
// @Security CoderSessionToken
Expand All @@ -37,11 +29,7 @@ func (api *API) oAuth2ProviderApps(rw http.ResponseWriter, r *http.Request) {
httpapi.InternalServerError(rw, err)
return
}
apps := []codersdk.OAuth2ProviderApp{}
for _, app := range dbApps {
apps = append(apps, convertApp(app))
}
httpapi.Write(ctx, rw, http.StatusOK, apps)
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApps(dbApps))
}

// @Summary Get OAuth2 application.
Expand All @@ -55,7 +43,7 @@ func (api *API) oAuth2ProviderApps(rw http.ResponseWriter, r *http.Request) {
func (*API) oAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
app := httpmw.OAuth2ProviderApp(r)
httpapi.Write(ctx, rw, http.StatusOK, convertApp(app))
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(app))
}

// @Summary Create OAuth2 application.
Expand Down Expand Up @@ -88,7 +76,7 @@ func (api *API) postOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
})
return
}
httpapi.Write(ctx, rw, http.StatusCreated, convertApp(app))
httpapi.Write(ctx, rw, http.StatusCreated, db2sdk.OAuth2ProviderApp(app))
}

// @Summary Update OAuth2 application.
Expand Down Expand Up @@ -122,7 +110,7 @@ func (api *API) putOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
})
return
}
httpapi.Write(ctx, rw, http.StatusOK, convertApp(app))
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(app))
}

// @Summary Delete OAuth2 application.
Expand Down