8000 wip: endpoints, remove after rebase · coder/coder@c5cc825 · GitHub
[go: up one dir, main page]

Skip to content

Commit c5cc825

Browse files
committed
wip: endpoints, remove after rebase
1 parent e3beb7d commit c5cc825

File tree

10 files changed

+188
-33
lines changed
  • enterprise/coderd
  • site/src
  • 10 files changed

    +188
    -33
    lines changed

    coderd/apidoc/docs.go

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

    coderd/database/db2sdk/db2sdk.go

    Lines changed: 14 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4,6 +4,7 @@ package db2sdk
    44
    import (
    55
    "encoding/json"
    66
    "fmt"
    7+
    "net/url"
    78
    "strconv"
    89
    "strings"
    910
    "time"
    @@ -226,19 +227,29 @@ func templateVersionParameterOptions(rawOptions json.RawMessage) ([]codersdk.Tem
    226227
    return options, nil
    227228
    }
    228229

    229-
    func OAuth2ProviderApp(dbApp database.OAuth2ProviderApp) codersdk.OAuth2ProviderApp {
    230+
    func OAuth2ProviderApp(accessURL *url.URL, dbApp database.OAuth2ProviderApp) codersdk.OAuth2ProviderApp {
    230231
    return codersdk.OAuth2ProviderApp{
    231232
    ID: dbApp.ID,
    232233
    Name: dbApp.Name,
    233234
    CallbackURL: dbApp.CallbackURL,
    234235
    Icon: dbApp.Icon,
    236+
    Endpoints: codersdk.OAuth2AppEndpoints{
    237+
    Authorization: accessURL.ResolveReference(&url.URL{
    238+
    Path: "/login/oauth2/authorize",
    239+
    }).String(),
    240+
    Token: accessURL.ResolveReference(&url.URL{
    241+
    Path: "/login/oauth2/tokens",
    242+
    }).String(),
    243+
    // We do not currently support DeviceAuth.
    244+
    DeviceAuth: "",
    245+
    },
    235246
    }
    236247
    }
    237248

    238-
    func OAuth2ProviderApps(dbApps []database.OAuth2ProviderApp) []codersdk.OAuth2ProviderApp {
    249+
    func OAuth2ProviderApps(accessURL *url.URL, dbApps []database.OAuth2ProviderApp) []codersdk.OAuth2ProviderApp {
    239250
    apps := []codersdk.OAuth2ProviderApp{}
    240251
    for _, dbApp := range dbApps {
    241-
    apps = append(apps, OAuth2ProviderApp(dbApp))
    252+
    apps = append(apps, OAuth2ProviderApp(accessURL, dbApp))
    242253
    }
    243254
    return apps
    244255
    }

    codersdk/oauth2.go

    Lines changed: 12 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,6 +14,18 @@ type OAuth2ProviderApp struct {
    1414
    Name string `json:"name"`
    1515
    CallbackURL string `json:"callback_url"`
    1616
    Icon string `json:"icon"`
    17+
    18+
    // Endpoints are included in the app response for easier discovery. The OAuth2
    19+
    // spec does not have a defined place to find these (for comparison, OIDC has
    20+
    // a '/.well-known/openid-configuration' endpoint).
    21+
    Endpoints OAuth2AppEndpoints `json:"endpoints"`
    22+
    }
    23+
    24+
    type OAuth2AppEndpoints struct {
    25+
    Authorization string `json:"authorization"`
    26+
    Token string `json:"token"`
    27+
    // DeviceAuth is optional.
    28+
    DeviceAuth string `json:"device_authorization"`
    1729
    }
    1830

    1931
    type OAuth2ProviderAppFilter struct {

    docs/api/enterprise.md

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

    docs/api/schemas.md

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

    enterprise/coderd/oauth2.go

    Lines changed: 6 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -62,7 +62,7 @@ func (api *API) oAuth2ProviderApps(rw http.ResponseWriter, r *http.Request) {
    6262
    httpapi.InternalServerError(rw, err)
    6363
    return
    6464
    }
    65-
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApps(dbApps))
    65+
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApps(api.AccessURL, dbApps))
    6666
    return
    6767
    }
    6868

    @@ -90,7 +90,7 @@ func (api *API) oAuth2ProviderApps(rw http.ResponseWriter, r *http.Request) {
    9090
    Icon: app.OAuth2ProviderApp.Icon,
    9191
    })
    9292
    }
    93-
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApps(dbApps))
    93+
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApps(api.AccessURL, dbApps))
    9494
    }
    9595

    9696
    // @Summary Get OAuth2 application.
    @@ -101,10 +101,10 @@ func (api *API) oAuth2ProviderApps(rw http.ResponseWriter, r *http.Request) {
    101101
    // @Param app path string true "App ID"
    102102
    // @Success 200 {object} codersdk.OAuth2ProviderApp
    103103
    // @Router /oauth2-provider/apps/{app} [get]
    104-
    func (*API) oAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
    104+
    func (api *API) oAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
    105105
    ctx := r.Context()
    106106
    app := httpmw.OAuth2ProviderApp(r)
    107-
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(app))
    107+
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(api.AccessURL, app))
    108108
    }
    109109

    110110
    // @Summary Create OAuth2 application.
    @@ -137,7 +137,7 @@ func (api *API) postOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
    137137
    })
    138138
    return
    139139
    }
    140-
    httpapi.Write(ctx, rw, http.StatusCreated, db2sdk.OAuth2ProviderApp(app))
    140+
    httpapi.Write(ctx, rw, http.StatusCreated, db2sdk.OAuth2ProviderApp(api.AccessURL, app))
    141141
    }
    142142

    143143
    // @Summary Update OAuth2 application.
    @@ -171,7 +171,7 @@ func (api *API) putOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request) {
    171171
    })
    172172
    return
    173173
    }
    174-
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(app))
    174+
    httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApp(api.AccessURL, app))
    175175
    }
    176176

    177177
    // @Summary Delete OAuth2 application.

    site/src/api/typesGenerated.ts

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

    site/src/pages/DeploySettingsPage/OAuth2AppsSettingsPage/EditOAuth2AppPageView.tsx

    Lines changed: 36 additions & 11 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,4 +1,4 @@
    1-
    import { useTheme } from "@emotion/react";
    1+
    import { type Interpolation, type Theme, useTheme } from "@emotion/react";
    22
    import CopyIcon from "@mui/icons-material/FileCopyOutlined";
    33
    import KeyboardArrowLeft from "@mui/icons-material/KeyboardArrowLeft";
    44
    import Divider from "@mui/material/Divider";
    @@ -139,16 +139,28 @@ export const EditOAuth2AppPageView: FC<EditOAuth2AppProps> = ({
    139139
    onCancel={() => setShowDelete(false)}
    140140
    />
    141141

    142-
    <h2 css={{ marginBottom: 0 }}>Client ID</h2>
    143-
    <CopyableValue value={app.id}>
    144-
    {app.id}{" "}
    145-
    <CopyIcon
    146-
    css={{
    147-
    width: 16,
    148-
    height: 16,
    149-
    }}
    150-
    />
    151-
    </CopyableValue>
    142+
    <dl css={styles.dataList}>
    143+
    <dt>Client ID</dt>
    144+
    <dd>
    145+
    <CopyableValue value={app.id}>
    146+
    {app.id} <CopyIcon css={{ width: 16, height: 16 }} />
    147+
    </CopyableValue>
    148+
    </dd>
    149+
    <dt>Authorization URL</dt>
    150+
    <dd>
    151+
    <CopyableValue value={app.endpoints.authorization}>
    152+
    {app.endpoints.authorization}{" "}
    153+
    <CopyIcon css={{ width: 16, height: 16 }} />
    154+
    </CopyableValue>
    155+
    </dd>
    156+
    <dt>Token URL</dt>
    157+
    <dd>
    158+
    <CopyableValue value={app.endpoints.token}>
    159+
    {app.endpoints.token}{" "}
    160+
    <CopyIcon css={{ width: 16, height: 16 }} />
    161+
    </CopyableValue>
    162+
    </dd>
    163+
    </dl>
    152164

    153165
    <Divider css={{ borderColor: theme.palette.divider }} />
    154166

    @@ -303,3 +315,16 @@ const OAuth2SecretRow: FC<OAuth2SecretRowProps> = ({
    303315
    </TableRow>
    304316
    );
    305317
    };
    7D25
    318+
    319+
    const styles = {
    320+
    dataList: {
    321+
    display: "grid",
    322+
    gridTemplateColumns: "max-content auto",
    323+
    "& > dt": {
    324+
    fontWeight: "bold",
    325+
    },
    326+
    "& > dd": {
    327+
    marginLeft: 10,
    328+
    },
    329+
    },
    330+
    } satisfies Record<string, Interpolation<Theme>>;

    0 commit comments

    Comments
     (0)
    0