Skip to content

Commit 331f8a4

Browse files
committed
feat: specify a custom terms of service link
1 parent 3f21cb8 commit 331f8a4

File tree

8 files changed

+47
-8
lines changed

8 files changed

+47
-8
lines changed

coderd/userauth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ func (api *API) userAuthMethods(rw http.ResponseWriter, r *http.Request) {
472472
}
473473

474474
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.AuthMethods{
475+
TermsOfServiceLink: api.DeploymentValues.TermsOfServiceLink.Value(),
475476
Password: codersdk.AuthMethod{
476477
Enabled: !api.DeploymentValues.DisablePasswordAuth.Value(),
477478
},
@@ -486,7 +487,7 @@ func (api *API) userAuthMethods(rw http.ResponseWriter, r *http.Request) {
486487

487488
// @Summary OAuth 2.0 GitHub Callback
488489
// @ID oauth-20-github-callback
489-
// @Security CoderSessionToken
490+
// @Security CoderSessionTokens
490491
// @Tags Users
491492
// @Success 307
492493
// @Router /users/oauth2/github/callback [get]

codersdk/deployment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ type DeploymentValues struct {
200200
AllowWorkspaceRenames serpent.Bool `json:"allow_workspace_renames,omitempty" typescript:",notnull"`
201201
Healthcheck HealthcheckConfig `json:"healthcheck,omitempty" typescript:",notnull"`
202202
CLIUpgradeMessage serpent.String `json:"cli_upgrade_message,omitempty" typescript:",notnull"`
203+
TermsOfServiceLink serpent.String `json:"terms_of_service_link,omitempty" typescript:",notnull"`
203204

204205
Config serpent.YAMLConfigPath `json:"config,omitempty" typescript:",notnull"`
205206
WriteConfig serpent.Bool `json:"write_config,omitempty" typescript:",notnull"`
@@ -1683,6 +1684,14 @@ when required by your organization's security policy.`,
16831684
YAML: "secureAuthCookie",
16841685
Annotations: serpent.Annotations{}.Mark(annotationExternalProxies, "true"),
16851686
},
1687+
{
1688+
Name: "Terms of Service Link",
1689+
Description: "A link to an external Terms of Service that must be accepted by users when logging in.",
1690+
Flag: "terms-of-service-link",
1691+
Env: "CODER_TERMS_OF_SERVICE_LINK",
1692+
YAML: "termsOfServiceLink",
1693+
Value: &c.TermsOfServiceLink,
1694+
},
16861695
{
16871696
Name: "Strict-Transport-Security",
16881697
Description: "Controls if the 'Strict-Transport-Security' header is set on all static file responses. " +

codersdk/users.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,10 @@ type CreateOrganizationRequest struct {
209209

210210
// AuthMethods contains authentication method information like whether they are enabled or not or custom text, etc.
211211
type AuthMethods struct {
212-
Password AuthMethod `json:"password"`
213-
Github AuthMethod `json:"github"`
214-
OIDC OIDCAuthMethod `json:"oidc"`
212+
TermsOfServiceLink string `json:"terms_of_service_link,omitempty"`
213+
Password AuthMethod `json:"password"`
214+
Github AuthMethod `json:"github"`
215+
OIDC OIDCAuthMethod `json:"oidc"`
215216
}
216217

217218
type AuthMethod struct {

site/src/api/typesGenerated.ts

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

site/src/pages/LoginPage/LoginPageView.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
MockAuthMethodsAll,
44
MockAuthMethodsExternal,
55
MockAuthMethodsPasswordOnly,
6+
MockAuthMethodsPasswordTermsOfService,
67
mockApiError,
78
} from "testHelpers/entities";
89
import { LoginPageView } from "./LoginPageView";
@@ -33,6 +34,12 @@ export const WithAllAuthMethods: Story = {
3334
},
3435
};
3536

37+
export const WithTermsOfService: Story = {
38+
args: {
39+
authMethods: MockAuthMethodsPasswordTermsOfService,
40+
},
41+
};
42+
3643
export const AuthError: Story = {
3744
args: {
3845
error: mockApiError({
@@ -53,6 +60,7 @@ export const ExternalAuthError: Story = {
5360

5461
export const LoadingAuthMethods: Story = {
5562
args: {
63+
isLoading: true,
5664
authMethods: undefined,
5765
},
5866
};

site/src/pages/LoginPage/SignInForm.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import type { Interpolation, Theme } from "@emotion/react";
2+
import Checkbox from "@mui/material/Checkbox";
23
import type { FC, ReactNode } from "react";
34
import type { AuthMethods } from "api/typesGenerated";
45
import { Alert } from "components/Alert/Alert";
56
import { ErrorAlert } from "components/Alert/ErrorAlert";
67
import { getApplicationName } from "utils/appearance";
78
import { OAuthSignInForm } from "./OAuthSignInForm";
89
import { PasswordSignInForm } from "./PasswordSignInForm";
10+
import { Link } from "@mui/material";
911

1012
export const Language = {
1113
emailLabel: "Email",
@@ -123,6 +125,18 @@ export const SignInForm: FC<SignInFormProps> = ({
123125
/>
124126
)}
125127

128+
{authMethods?.terms_of_service_link && (
129+
<div css={{ paddingTop: 8, fontSize: 14 }}>
130+
<label>
131+
<Checkbox size="small" />I agree to the{" "}
132+
<Link href={authMethods.terms_of_service_link} target="_blank">
133+
Terms of Service
134+
</Link>
135+
.
136+
</label>
137+
</div>
138+
)}
139+
126140
{!passwordEnabled && !oAuthEnabled && (
127141
<Alert severity="error">No authentication methods configured!</Alert>
128142
)}

site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ export const SingleSignOnSection: FC<SingleSignOnSectionProps> = ({
136136
}) => {
137137
const theme = useTheme();
138138

139-
const authList = Object.values(
140-
authMethods,
141-
) as (typeof authMethods)[keyof typeof authMethods][];
142-
const noSsoEnabled = !authList.some((method) => method.enabled);
139+
const noSsoEnabled = !authMethods.github.enabled && !authMethods.oidc.enabled;
143140

144141
return (
145142
<>

site/src/testHelpers/entities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,13 @@ export const MockAuthMethodsPasswordOnly: TypesGen.AuthMethods = {
13731373
oidc: { enabled: false, signInText: "", iconUrl: "" },
13741374
};
13751375

1376+
export const MockAuthMethodsPasswordTermsOfService: TypesGen.AuthMethods = {
1377+
terms_of_service_link: "https://www.youtube.com/watch?v=C2f37Vb2NAE",
1378+
password: { enabled: true },
1379+
github: { enabled: false },
1380+
oidc: { enabled: false, signInText: "", iconUrl: "" },
1381+
};
1382+
13761383
export const MockAuthMethodsExternal: TypesGen.AuthMethods = {
13771384
password: { enabled: false },
13781385
github: { enabled: true },

0 commit comments

Comments
 (0)