@nocobase/portal-template-default 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +77 -0
- package/package.json +23 -17
- package/registry/nocobase-acl/demo/prompt-generator.tsx +6 -39
- package/registry/nocobase-acl/demo/role-switcher-prompt-generator.tsx +6 -42
- package/registry/nocobase-ai/demo/page-context-prompt-generator.tsx +1 -1
- package/registry/nocobase-ai/demo/prompt-card.tsx +7 -28
- package/registry/nocobase-ai/demo/prompt-generator.tsx +9 -30
- package/registry/nocobase-ai/demo/shortcut.tsx +1 -1
- package/registry/nocobase-ai/demo/tool-cards.tsx +10 -30
- package/registry/nocobase-auth-cas/README.md +6 -0
- package/registry/nocobase-auth-cas/cas-sign-in-button.tsx +41 -0
- package/registry/nocobase-auth-cas/demo.tsx +20 -0
- package/registry/nocobase-auth-cas/extension.tsx +46 -0
- package/registry/nocobase-auth-cas/index.ts +1 -0
- package/registry/nocobase-auth-cas/use-cas-sign-in.ts +29 -0
- package/registry/nocobase-auth-dingtalk/README.md +7 -0
- package/registry/nocobase-auth-dingtalk/auto-login-provider.tsx +154 -0
- package/registry/nocobase-auth-dingtalk/demo.tsx +23 -0
- package/registry/nocobase-auth-dingtalk/dingtalk-sign-in-button.tsx +45 -0
- package/registry/nocobase-auth-dingtalk/extension.tsx +55 -0
- package/registry/nocobase-auth-dingtalk/index.ts +4 -0
- package/registry/nocobase-auth-dingtalk/use-dingtalk-sign-in.ts +64 -0
- package/registry/nocobase-auth-ldap/README.md +6 -0
- package/registry/nocobase-auth-ldap/demo.tsx +21 -0
- package/registry/nocobase-auth-ldap/extension.tsx +46 -0
- package/registry/nocobase-auth-ldap/index.ts +1 -0
- package/registry/nocobase-auth-ldap/ldap-sign-in-form.tsx +69 -0
- package/registry/nocobase-auth-ldap/use-ldap-sign-in.ts +5 -0
- package/registry/nocobase-auth-oidc/README.md +11 -0
- package/registry/nocobase-auth-oidc/auto-redirect-provider.tsx +13 -0
- package/registry/nocobase-auth-oidc/demo.tsx +20 -0
- package/registry/nocobase-auth-oidc/extension.tsx +51 -0
- package/registry/nocobase-auth-oidc/index.ts +1 -0
- package/registry/nocobase-auth-oidc/oidc-sign-in-button.tsx +44 -0
- package/registry/nocobase-auth-oidc/use-oidc-sign-in.ts +58 -0
- package/registry/nocobase-auth-saml/README.md +6 -0
- package/registry/nocobase-auth-saml/auto-redirect-provider.tsx +13 -0
- package/registry/nocobase-auth-saml/demo.tsx +20 -0
- package/registry/nocobase-auth-saml/extension.tsx +51 -0
- package/registry/nocobase-auth-saml/index.ts +1 -0
- package/registry/nocobase-auth-saml/saml-sign-in-button.tsx +43 -0
- package/registry/nocobase-auth-saml/use-saml-sign-in.ts +51 -0
- package/registry/nocobase-auth-sms/README.md +7 -0
- package/registry/nocobase-auth-sms/demo.tsx +25 -0
- package/registry/nocobase-auth-sms/extension.tsx +46 -0
- package/registry/nocobase-auth-sms/index.ts +1 -0
- package/registry/nocobase-auth-sms/sms-sign-in-form.tsx +107 -0
- package/registry/nocobase-auth-sms/use-sms-sign-in.ts +88 -0
- package/registry/nocobase-auth-wecom/README.md +6 -0
- package/registry/nocobase-auth-wecom/auto-login-provider.tsx +21 -0
- package/registry/nocobase-auth-wecom/demo.tsx +23 -0
- package/registry/nocobase-auth-wecom/extension.tsx +49 -0
- package/registry/nocobase-auth-wecom/index.ts +1 -0
- package/registry/nocobase-auth-wecom/use-wecom-sign-in.ts +62 -0
- package/registry/nocobase-auth-wecom/wecom-sign-in-button.tsx +70 -0
- package/registry/nocobase-i18n/demo/prompt-generator.tsx +30 -54
- package/registry/nocobase-route-surfaces/demo/prompt-generator.tsx +18 -21
- package/registry.config.json +112 -0
- package/scripts/build-html.mjs +106 -0
- package/src/App.tsx +34 -8
- package/src/app/extension.ts +4 -0
- package/src/app/extensions.tsx +24 -1
- package/src/components/auth/authenticator-adapters.ts +20 -0
- package/src/components/auth/auto-redirect-provider.tsx +84 -0
- package/src/components/auth/basic-sign-in-form.tsx +101 -0
- package/src/components/auth/default-sign-in-page.tsx +20 -0
- package/src/components/auth/demo/auth-demo-page.tsx +236 -0
- package/src/components/auth/demo/auth-demo-prompt-generator.tsx +93 -0
- package/src/components/auth/demo/auth-demo-route.tsx +11 -0
- package/src/components/auth/demo/auth-method-demo.tsx +48 -0
- package/src/components/auth/demo/index.ts +4 -0
- package/src/components/auth/dynamic-sign-in.tsx +191 -0
- package/src/components/auth/forgot-password-form.tsx +13 -5
- package/src/components/auth/index.ts +13 -0
- package/src/components/auth/sign-in-form.tsx +1 -111
- package/src/components/auth/sign-up-form.tsx +14 -37
- package/src/components/auth/types.ts +38 -0
- package/src/components/auth/use-authenticator-sign-in.ts +14 -0
- package/src/components/auth/use-public-authenticators.ts +26 -0
- package/src/components/data-table/data-table-filter.tsx +107 -153
- package/src/components/demo/prompt-output.tsx +71 -0
- package/src/components/ui/alert-dialog.tsx +2 -0
- package/src/components/ui/attachment.tsx +207 -0
- package/src/components/ui/bubble.tsx +128 -0
- package/src/components/ui/button-group.tsx +87 -0
- package/src/components/ui/button.tsx +6 -6
- package/src/components/ui/calendar.tsx +0 -2
- package/src/components/ui/card.tsx +1 -1
- package/src/components/ui/carousel.tsx +2 -0
- package/src/components/ui/combobox.tsx +297 -0
- package/src/components/ui/command.tsx +43 -41
- package/src/components/ui/dialog.tsx +0 -2
- package/src/components/ui/direction.tsx +4 -0
- package/src/components/ui/drawer.tsx +2 -0
- package/src/components/ui/dropdown-menu.tsx +0 -2
- package/src/components/ui/empty.tsx +104 -0
- package/src/components/ui/field.tsx +238 -0
- package/src/components/ui/hover-card.tsx +2 -0
- package/src/components/ui/input-group.tsx +0 -2
- package/src/components/ui/input-otp.tsx +0 -2
- package/src/components/ui/input.tsx +1 -1
- package/src/components/ui/item.tsx +201 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +2 -0
- package/src/components/ui/marker.tsx +71 -0
- package/src/components/ui/message-scroller.tsx +131 -0
- package/src/components/ui/message.tsx +92 -0
- package/src/components/ui/native-select.tsx +61 -0
- package/src/components/ui/popover.tsx +0 -2
- package/src/components/ui/progress.tsx +2 -0
- package/src/components/ui/radio-group.tsx +0 -2
- package/src/components/ui/resizable.tsx +2 -0
- package/src/components/ui/scroll-area.tsx +0 -2
- package/src/components/ui/select.tsx +6 -4
- package/src/components/ui/separator.tsx +0 -2
- package/src/components/ui/sheet.tsx +21 -22
- package/src/components/ui/sidebar.tsx +1 -3
- package/src/components/ui/sonner.tsx +2 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/switch.tsx +0 -2
- package/src/components/ui/table.tsx +4 -2
- package/src/components/ui/tabs.tsx +0 -2
- package/src/components/ui/textarea.tsx +1 -1
- package/src/components/ui/toggle-group.tsx +2 -0
- package/src/components/ui/toggle.tsx +2 -0
- package/src/components/ui/tooltip.tsx +0 -2
- package/src/index.tsx +3 -0
- package/src/lib/nocobase/client.ts +32 -2
- package/src/lib/utils.ts +2 -1
- package/src/locales/en-US.ts +4 -2
- package/src/locales/zh-CN.ts +4 -2
- package/src/pages/login/index.tsx +2 -2
- package/src/pages/users/list.tsx +144 -16
- package/src/providers/auth-callback.ts +21 -0
- package/src/providers/auth.ts +108 -22
- package/src/providers/constants.ts +4 -1
- package/src/providers/runtime-config.ts +19 -0
- package/src/vite-env.d.ts +5 -0
- package/vite.config.ts +55 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { useSearchParams } from "react-router";
|
|
3
|
+
|
|
4
|
+
import type { Authenticator } from "@/components/auth/types";
|
|
5
|
+
import { nocobaseClient } from "@/lib/nocobase/client";
|
|
6
|
+
|
|
7
|
+
export function useCasSignIn(authenticator: Authenticator) {
|
|
8
|
+
const [searchParams] = useSearchParams();
|
|
9
|
+
const callbackError = useMemo(() => {
|
|
10
|
+
if (searchParams.get("authenticator") !== authenticator.name) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const message = searchParams.get("error");
|
|
14
|
+
return message ? new Error(message) : undefined;
|
|
15
|
+
}, [authenticator.name, searchParams]);
|
|
16
|
+
|
|
17
|
+
const signIn = useCallback(() => {
|
|
18
|
+
const redirect =
|
|
19
|
+
searchParams.get("to") || searchParams.get("redirect") || "/";
|
|
20
|
+
const url = nocobaseClient.buildUrl("cas:login", {
|
|
21
|
+
authenticator: authenticator.name,
|
|
22
|
+
__appName: "main",
|
|
23
|
+
redirect,
|
|
24
|
+
});
|
|
25
|
+
window.location.replace(url.toString());
|
|
26
|
+
}, [authenticator.name, searchParams]);
|
|
27
|
+
|
|
28
|
+
return { signIn, error: callbackError };
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# NocoBase DingTalk authentication
|
|
2
|
+
|
|
3
|
+
Adds DingTalk OAuth sign-in, callback errors, OAuth or micro-app automatic
|
|
4
|
+
login, and `useDingtalkSignIn` for custom UI. The DingTalk JSAPI is loaded only
|
|
5
|
+
inside a DingTalk browser during internal automatic login.
|
|
6
|
+
|
|
7
|
+
Installing the Registry also adds a DingTalk component Demo under Authentication.
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useLocation } from "react-router";
|
|
3
|
+
|
|
4
|
+
import { LoadingState } from "@/components/app-shell/loading-state";
|
|
5
|
+
import { clearAcl } from "@/lib/nocobase/acl";
|
|
6
|
+
import { nocobaseClient } from "@/lib/nocobase/client";
|
|
7
|
+
|
|
8
|
+
import { isDingtalkBrowser } from "./use-dingtalk-sign-in";
|
|
9
|
+
|
|
10
|
+
type CheckLoginResponse = {
|
|
11
|
+
success?: boolean;
|
|
12
|
+
autoLoginType?: "oauth" | "internal";
|
|
13
|
+
authUrl?: string;
|
|
14
|
+
authenticator?: string;
|
|
15
|
+
corpId?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type SignInResponse = {
|
|
19
|
+
token?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const publicAuthPaths = new Set([
|
|
23
|
+
"/login",
|
|
24
|
+
"/signin",
|
|
25
|
+
"/register",
|
|
26
|
+
"/forgot-password",
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
async function requestDingtalkAuthCode(corpId: string) {
|
|
30
|
+
const module = await import("dingtalk-jsapi");
|
|
31
|
+
const dd = ((module as { default?: unknown }).default ?? module) as any;
|
|
32
|
+
|
|
33
|
+
return new Promise<string>((resolve, reject) => {
|
|
34
|
+
const success = (result: { code?: string; authCode?: string }) => {
|
|
35
|
+
const code = result?.code ?? result?.authCode;
|
|
36
|
+
code
|
|
37
|
+
? resolve(String(code))
|
|
38
|
+
: reject(new Error("DingTalk did not return an authorization code."));
|
|
39
|
+
};
|
|
40
|
+
const fail = (error: { errorMessage?: string; message?: string }) =>
|
|
41
|
+
reject(
|
|
42
|
+
new Error(
|
|
43
|
+
error?.errorMessage ||
|
|
44
|
+
error?.message ||
|
|
45
|
+
"Unable to request a DingTalk authorization code."
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
const run = () => {
|
|
49
|
+
const requestAuthCode = dd?.runtime?.permission?.requestAuthCode;
|
|
50
|
+
if (typeof requestAuthCode === "function") {
|
|
51
|
+
const result = requestAuthCode({ corpId, success, fail });
|
|
52
|
+
if (result?.then) result.then(success).catch(fail);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (typeof dd?.getAuthCode === "function") {
|
|
56
|
+
dd.getAuthCode({ corpId, success, fail });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
fail({ message: "DingTalk auth-code API is unavailable." });
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
typeof dd?.ready === "function" ? dd.ready(run) : run();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
fail(error as Error);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default function DingtalkAutoLoginProvider({
|
|
71
|
+
children,
|
|
72
|
+
}: React.PropsWithChildren) {
|
|
73
|
+
const { pathname, search } = useLocation();
|
|
74
|
+
const attemptedRef = useRef(false);
|
|
75
|
+
const insideDingtalk = isDingtalkBrowser();
|
|
76
|
+
const redirect = `${pathname}${search}`;
|
|
77
|
+
const shouldCheck =
|
|
78
|
+
insideDingtalk &&
|
|
79
|
+
!nocobaseClient.getToken() &&
|
|
80
|
+
!publicAuthPaths.has(pathname);
|
|
81
|
+
const [isChecking, setIsChecking] = useState(shouldCheck);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!shouldCheck || attemptedRef.current) {
|
|
85
|
+
setIsChecking(false);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
attemptedRef.current = true;
|
|
89
|
+
setIsChecking(true);
|
|
90
|
+
const controller = new AbortController();
|
|
91
|
+
|
|
92
|
+
void (async () => {
|
|
93
|
+
try {
|
|
94
|
+
const result = await nocobaseClient.action<CheckLoginResponse>(
|
|
95
|
+
"dingtalk",
|
|
96
|
+
"checkLogin",
|
|
97
|
+
{
|
|
98
|
+
method: "GET",
|
|
99
|
+
query: { isDingTalkBrowser: true, redirect },
|
|
100
|
+
signal: controller.signal,
|
|
101
|
+
authenticator: null,
|
|
102
|
+
includeRole: false,
|
|
103
|
+
withAclMeta: false,
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
if (result?.success !== false) return;
|
|
108
|
+
if (result.autoLoginType === "oauth" && result.authUrl) {
|
|
109
|
+
window.location.replace(nocobaseClient.resolveUrl(result.authUrl));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (
|
|
113
|
+
result.autoLoginType !== "internal" ||
|
|
114
|
+
!result.authenticator ||
|
|
115
|
+
!result.corpId
|
|
116
|
+
) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const authCode = await requestDingtalkAuthCode(result.corpId);
|
|
121
|
+
const signedIn = await nocobaseClient.action<SignInResponse>(
|
|
122
|
+
"auth",
|
|
123
|
+
"signIn",
|
|
124
|
+
{
|
|
125
|
+
method: "POST",
|
|
126
|
+
authenticator: result.authenticator,
|
|
127
|
+
body: { authCode, loginType: "internal" },
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
if (!signedIn.token) {
|
|
131
|
+
throw new Error("NocoBase did not return an access token.");
|
|
132
|
+
}
|
|
133
|
+
nocobaseClient.setAuthenticator(result.authenticator);
|
|
134
|
+
nocobaseClient.setToken(signedIn.token);
|
|
135
|
+
nocobaseClient.setRole(null);
|
|
136
|
+
clearAcl();
|
|
137
|
+
window.location.replace(redirect);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (!(error instanceof DOMException && error.name === "AbortError")) {
|
|
140
|
+
console.warn("Unable to complete DingTalk automatic login", error);
|
|
141
|
+
}
|
|
142
|
+
} finally {
|
|
143
|
+
setIsChecking(false);
|
|
144
|
+
}
|
|
145
|
+
})();
|
|
146
|
+
|
|
147
|
+
return () => controller.abort();
|
|
148
|
+
}, [redirect, shouldCheck]);
|
|
149
|
+
|
|
150
|
+
if (isChecking) {
|
|
151
|
+
return <LoadingState className="min-h-svh" />;
|
|
152
|
+
}
|
|
153
|
+
return children;
|
|
154
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuthMethodDemo } from "@/components/auth/demo";
|
|
2
|
+
import DingtalkSignInButton from "./dingtalk-sign-in-button";
|
|
3
|
+
|
|
4
|
+
const authenticator = {
|
|
5
|
+
name: "company-dingtalk",
|
|
6
|
+
authType: "dingtalk",
|
|
7
|
+
title: "Sign in via DingTalk",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function DingtalkAuthDemoPage() {
|
|
11
|
+
return (
|
|
12
|
+
<AuthMethodDemo
|
|
13
|
+
authType="dingtalk"
|
|
14
|
+
methodName="DingTalk"
|
|
15
|
+
description="Provide DingTalk OAuth login and support internal micro-app automatic login through DingTalk JSAPI."
|
|
16
|
+
>
|
|
17
|
+
<DingtalkSignInButton
|
|
18
|
+
authenticator={authenticator}
|
|
19
|
+
onSignIn={() => {}}
|
|
20
|
+
/>
|
|
21
|
+
</AuthMethodDemo>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MessageSquare } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
import type { AuthenticatorComponentProps } from "@/components/auth/types";
|
|
4
|
+
import {
|
|
5
|
+
Alert,
|
|
6
|
+
AlertDescription,
|
|
7
|
+
AlertTitle,
|
|
8
|
+
} from "@/components/ui/alert";
|
|
9
|
+
import { Button } from "@/components/ui/button";
|
|
10
|
+
import { resolveTranslatableText } from "@/lib/i18n";
|
|
11
|
+
|
|
12
|
+
import { useDingtalkSignIn } from "./use-dingtalk-sign-in";
|
|
13
|
+
|
|
14
|
+
export default function DingtalkSignInButton({
|
|
15
|
+
authenticator,
|
|
16
|
+
onSignIn,
|
|
17
|
+
}: AuthenticatorComponentProps & { onSignIn?: () => void }) {
|
|
18
|
+
const { signIn, isPending, error } = useDingtalkSignIn(authenticator);
|
|
19
|
+
return (
|
|
20
|
+
<div className="space-y-3">
|
|
21
|
+
{error && (
|
|
22
|
+
<Alert variant="destructive">
|
|
23
|
+
<AlertTitle>DingTalk sign-in failed</AlertTitle>
|
|
24
|
+
<AlertDescription>{error.message}</AlertDescription>
|
|
25
|
+
</Alert>
|
|
26
|
+
)}
|
|
27
|
+
<Button
|
|
28
|
+
type="button"
|
|
29
|
+
variant="outline"
|
|
30
|
+
className="w-full"
|
|
31
|
+
disabled={!onSignIn && isPending}
|
|
32
|
+
onClick={onSignIn ?? signIn}
|
|
33
|
+
>
|
|
34
|
+
<MessageSquare />
|
|
35
|
+
{!onSignIn && isPending
|
|
36
|
+
? "Redirecting…"
|
|
37
|
+
: resolveTranslatableText(
|
|
38
|
+
authenticator.title ||
|
|
39
|
+
authenticator.authTypeTitle ||
|
|
40
|
+
"Sign in via DingTalk"
|
|
41
|
+
)}
|
|
42
|
+
</Button>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { lazy } from "react";
|
|
2
|
+
import { MessageSquare } from "lucide-react";
|
|
3
|
+
import { Route } from "react-router";
|
|
4
|
+
|
|
5
|
+
import type { AppExtension } from "@/app/extension";
|
|
6
|
+
import { AuthDemoRoute } from "@/components/auth/demo";
|
|
7
|
+
|
|
8
|
+
const DingtalkSignInButton = lazy(
|
|
9
|
+
() => import("./dingtalk-sign-in-button")
|
|
10
|
+
);
|
|
11
|
+
const DingtalkAutoLoginProvider = lazy(
|
|
12
|
+
() => import("./auto-login-provider")
|
|
13
|
+
);
|
|
14
|
+
const DingtalkAuthDemoPage = lazy(() =>
|
|
15
|
+
import("./demo").then((module) => ({
|
|
16
|
+
default: module.DingtalkAuthDemoPage,
|
|
17
|
+
}))
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const dingtalkAuthExtension: AppExtension = {
|
|
21
|
+
id: "nocobase-auth-dingtalk",
|
|
22
|
+
AuthRuntimeProvider: DingtalkAutoLoginProvider,
|
|
23
|
+
authRuntimePriority: 10,
|
|
24
|
+
resources: [
|
|
25
|
+
{
|
|
26
|
+
name: "auth-dingtalk-demo",
|
|
27
|
+
list: "/auth/dingtalk",
|
|
28
|
+
meta: {
|
|
29
|
+
parent: "auth-components",
|
|
30
|
+
label: "DingTalk",
|
|
31
|
+
icon: <MessageSquare />,
|
|
32
|
+
acl: { type: "authenticated" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
routes: (
|
|
37
|
+
<Route
|
|
38
|
+
path="/auth/dingtalk"
|
|
39
|
+
element={
|
|
40
|
+
<AuthDemoRoute>
|
|
41
|
+
<DingtalkAuthDemoPage />
|
|
42
|
+
</AuthDemoRoute>
|
|
43
|
+
}
|
|
44
|
+
/>
|
|
45
|
+
),
|
|
46
|
+
authAdapters: [
|
|
47
|
+
{
|
|
48
|
+
authType: "dingtalk",
|
|
49
|
+
placement: "button",
|
|
50
|
+
Component: DingtalkSignInButton,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default dingtalkAuthExtension;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { useSearchParams } from "react-router";
|
|
3
|
+
|
|
4
|
+
import type { Authenticator } from "@/components/auth/types";
|
|
5
|
+
import { nocobaseClient } from "@/lib/nocobase/client";
|
|
6
|
+
|
|
7
|
+
type DingtalkAuthUrlResponse = {
|
|
8
|
+
url?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function isDingtalkBrowser() {
|
|
12
|
+
return (
|
|
13
|
+
typeof navigator !== "undefined" &&
|
|
14
|
+
navigator.userAgent.toLowerCase().includes("dingtalk")
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function useDingtalkSignIn(authenticator: Authenticator) {
|
|
19
|
+
const [searchParams] = useSearchParams();
|
|
20
|
+
const [isPending, setIsPending] = useState(false);
|
|
21
|
+
const [error, setError] = useState<Error>();
|
|
22
|
+
const callbackError = useMemo(() => {
|
|
23
|
+
if (searchParams.get("authenticator") !== authenticator.name) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const message = searchParams.get("error");
|
|
27
|
+
return message ? new Error(message) : undefined;
|
|
28
|
+
}, [authenticator.name, searchParams]);
|
|
29
|
+
|
|
30
|
+
const signIn = useCallback(async () => {
|
|
31
|
+
setError(undefined);
|
|
32
|
+
setIsPending(true);
|
|
33
|
+
try {
|
|
34
|
+
const redirect =
|
|
35
|
+
searchParams.get("to") || searchParams.get("redirect") || "/";
|
|
36
|
+
const result = await nocobaseClient.action<DingtalkAuthUrlResponse>(
|
|
37
|
+
"dingtalk",
|
|
38
|
+
"getAuthUrl",
|
|
39
|
+
{
|
|
40
|
+
method: "POST",
|
|
41
|
+
authenticator: authenticator.name,
|
|
42
|
+
includeRole: false,
|
|
43
|
+
withAclMeta: false,
|
|
44
|
+
body: { redirect },
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
if (!result?.url) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"NocoBase did not return a DingTalk authorization URL."
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
window.location.replace(nocobaseClient.resolveUrl(result.url));
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
setError(
|
|
55
|
+
cause instanceof Error
|
|
56
|
+
? cause
|
|
57
|
+
: new Error("Unable to start DingTalk sign-in.")
|
|
58
|
+
);
|
|
59
|
+
setIsPending(false);
|
|
60
|
+
}
|
|
61
|
+
}, [authenticator.name, searchParams]);
|
|
62
|
+
|
|
63
|
+
return { signIn, isPending, error: error ?? callbackError };
|
|
64
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AuthMethodDemo } from "@/components/auth/demo";
|
|
2
|
+
import LdapSignInForm from "./ldap-sign-in-form";
|
|
3
|
+
|
|
4
|
+
const authenticator = {
|
|
5
|
+
name: "company-ldap",
|
|
6
|
+
authType: "LDAP",
|
|
7
|
+
title: "Company directory",
|
|
8
|
+
options: { autoSignup: true },
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function LdapAuthDemoPage() {
|
|
12
|
+
return (
|
|
13
|
+
<AuthMethodDemo
|
|
14
|
+
authType="LDAP"
|
|
15
|
+
methodName="LDAP directory"
|
|
16
|
+
description="Use the familiar account and password form while sending credentials through the selected LDAP authenticator."
|
|
17
|
+
>
|
|
18
|
+
<LdapSignInForm authenticator={authenticator} onSignIn={() => {}} />
|
|
19
|
+
</AuthMethodDemo>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { lazy } from "react";
|
|
2
|
+
import { ContactRound } from "lucide-react";
|
|
3
|
+
import { Route } from "react-router";
|
|
4
|
+
|
|
5
|
+
import type { AppExtension } from "@/app/extension";
|
|
6
|
+
import { AuthDemoRoute } from "@/components/auth/demo";
|
|
7
|
+
|
|
8
|
+
const LdapSignInForm = lazy(() => import("./ldap-sign-in-form"));
|
|
9
|
+
const LdapAuthDemoPage = lazy(() =>
|
|
10
|
+
import("./demo").then((module) => ({ default: module.LdapAuthDemoPage }))
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const ldapAuthExtension: AppExtension = {
|
|
14
|
+
id: "nocobase-auth-ldap",
|
|
15
|
+
resources: [
|
|
16
|
+
{
|
|
17
|
+
name: "auth-ldap-demo",
|
|
18
|
+
list: "/auth/ldap",
|
|
19
|
+
meta: {
|
|
20
|
+
parent: "auth-components",
|
|
21
|
+
label: "LDAP",
|
|
22
|
+
icon: <ContactRound />,
|
|
23
|
+
acl: { type: "authenticated" },
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
routes: (
|
|
28
|
+
<Route
|
|
29
|
+
path="/auth/ldap"
|
|
30
|
+
element={
|
|
31
|
+
<AuthDemoRoute>
|
|
32
|
+
<LdapAuthDemoPage />
|
|
33
|
+
</AuthDemoRoute>
|
|
34
|
+
}
|
|
35
|
+
/>
|
|
36
|
+
),
|
|
37
|
+
authAdapters: [
|
|
38
|
+
{
|
|
39
|
+
authType: "LDAP",
|
|
40
|
+
placement: "form",
|
|
41
|
+
Component: LdapSignInForm,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default ldapAuthExtension;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLdapSignIn } from "./use-ldap-sign-in";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { InputPassword } from "@/components/auth/input-password";
|
|
4
|
+
import type { AuthenticatorComponentProps } from "@/components/auth/types";
|
|
5
|
+
import { Button } from "@/components/ui/button";
|
|
6
|
+
import { Input } from "@/components/ui/input";
|
|
7
|
+
import { Label } from "@/components/ui/label";
|
|
8
|
+
|
|
9
|
+
import { useLdapSignIn } from "./use-ldap-sign-in";
|
|
10
|
+
|
|
11
|
+
export default function LdapSignInForm({
|
|
12
|
+
authenticator,
|
|
13
|
+
onSignIn,
|
|
14
|
+
}: AuthenticatorComponentProps & {
|
|
15
|
+
onSignIn?: (values: { account: string; password: string }) => void;
|
|
16
|
+
}) {
|
|
17
|
+
const [account, setAccount] = useState("");
|
|
18
|
+
const [password, setPassword] = useState("");
|
|
19
|
+
const { signIn, isPending } = useLdapSignIn(authenticator.name);
|
|
20
|
+
const autoSignup = authenticator.options?.autoSignup === true;
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<form
|
|
24
|
+
className="space-y-5"
|
|
25
|
+
onSubmit={(event) => {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
if (onSignIn) {
|
|
28
|
+
onSignIn({ account, password });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
void signIn({ account, password });
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<div className="space-y-2">
|
|
35
|
+
<Label htmlFor={`${authenticator.name}-ldap-account`}>Account</Label>
|
|
36
|
+
<Input
|
|
37
|
+
id={`${authenticator.name}-ldap-account`}
|
|
38
|
+
value={account}
|
|
39
|
+
onChange={(event) => setAccount(event.target.value)}
|
|
40
|
+
autoComplete="username"
|
|
41
|
+
required
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
<div className="space-y-2">
|
|
45
|
+
<Label htmlFor={`${authenticator.name}-ldap-password`}>Password</Label>
|
|
46
|
+
<InputPassword
|
|
47
|
+
id={`${authenticator.name}-ldap-password`}
|
|
48
|
+
value={password}
|
|
49
|
+
onChange={(event) => setPassword(event.target.value)}
|
|
50
|
+
autoComplete="current-password"
|
|
51
|
+
required
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
54
|
+
<Button
|
|
55
|
+
type="submit"
|
|
56
|
+
className="w-full"
|
|
57
|
+
disabled={!onSignIn && isPending}
|
|
58
|
+
>
|
|
59
|
+
{!onSignIn && isPending ? "Signing in…" : "Sign in"}
|
|
60
|
+
</Button>
|
|
61
|
+
{autoSignup && (
|
|
62
|
+
<p className="text-xs leading-5 text-muted-foreground">
|
|
63
|
+
An account will be created automatically after the first successful
|
|
64
|
+
LDAP sign-in.
|
|
65
|
+
</p>
|
|
66
|
+
)}
|
|
67
|
+
</form>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# NocoBase OIDC authentication
|
|
2
|
+
|
|
3
|
+
This Registry adds the default OIDC sign-in button to the Starter's dynamic
|
|
4
|
+
authentication page. It also exports `useOidcSignIn` so applications can keep
|
|
5
|
+
the NocoBase OIDC protocol while replacing the button UI.
|
|
6
|
+
|
|
7
|
+
Installing the Registry also adds an OIDC component Demo under Authentication.
|
|
8
|
+
|
|
9
|
+
The authenticator instance must be enabled in the connected NocoBase app. SSO
|
|
10
|
+
callbacks currently require the Portal and NocoBase public endpoints to share
|
|
11
|
+
an origin or use a compatible reverse proxy.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
|
|
3
|
+
import { AuthAutoRedirectProvider } from "@/components/auth";
|
|
4
|
+
|
|
5
|
+
export default function OidcAutoRedirectProvider({
|
|
6
|
+
children,
|
|
7
|
+
}: PropsWithChildren) {
|
|
8
|
+
return (
|
|
9
|
+
<AuthAutoRedirectProvider resource="oidc" action="checkRedirect">
|
|
10
|
+
{children}
|
|
11
|
+
</AuthAutoRedirectProvider>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthMethodDemo } from "@/components/auth/demo";
|
|
2
|
+
import OidcSignInButton from "./oidc-sign-in-button";
|
|
3
|
+
|
|
4
|
+
const authenticator = {
|
|
5
|
+
name: "company-oidc",
|
|
6
|
+
authType: "OIDC",
|
|
7
|
+
title: "Company OIDC",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function OidcAuthDemoPage() {
|
|
11
|
+
return (
|
|
12
|
+
<AuthMethodDemo
|
|
13
|
+
authType="OIDC"
|
|
14
|
+
methodName="OpenID Connect"
|
|
15
|
+
description="Redirect users to an OpenID Connect provider while the Starter handles callback tokens and the active authenticator."
|
|
16
|
+
>
|
|
17
|
+
<OidcSignInButton authenticator={authenticator} onSignIn={() => {}} />
|
|
18
|
+
</AuthMethodDemo>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { lazy } from "react";
|
|
2
|
+
import { LogIn } from "lucide-react";
|
|
3
|
+
import { Route } from "react-router";
|
|
4
|
+
|
|
5
|
+
import type { AppExtension } from "@/app/extension";
|
|
6
|
+
import { AuthDemoRoute } from "@/components/auth/demo";
|
|
7
|
+
|
|
8
|
+
const OidcSignInButton = lazy(() => import("./oidc-sign-in-button"));
|
|
9
|
+
const OidcAutoRedirectProvider = lazy(
|
|
10
|
+
() => import("./auto-redirect-provider")
|
|
11
|
+
);
|
|
12
|
+
const OidcAuthDemoPage = lazy(() =>
|
|
13
|
+
import("./demo").then((module) => ({ default: module.OidcAuthDemoPage }))
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const oidcAuthExtension: AppExtension = {
|
|
17
|
+
id: "nocobase-auth-oidc",
|
|
18
|
+
AuthRuntimeProvider: OidcAutoRedirectProvider,
|
|
19
|
+
authRuntimePriority: 20,
|
|
20
|
+
resources: [
|
|
21
|
+
{
|
|
22
|
+
name: "auth-oidc-demo",
|
|
23
|
+
list: "/auth/oidc",
|
|
24
|
+
meta: {
|
|
25
|
+
parent: "auth-components",
|
|
26
|
+
label: "OIDC",
|
|
27
|
+
icon: <LogIn />,
|
|
28
|
+
acl: { type: "authenticated" },
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
routes: (
|
|
33
|
+
<Route
|
|
34
|
+
path="/auth/oidc"
|
|
35
|
+
element={
|
|
36
|
+
<AuthDemoRoute>
|
|
37
|
+
<OidcAuthDemoPage />
|
|
38
|
+
</AuthDemoRoute>
|
|
39
|
+
}
|
|
40
|
+
/>
|
|
41
|
+
),
|
|
42
|
+
authAdapters: [
|
|
43
|
+
{
|
|
44
|
+
authType: "OIDC",
|
|
45
|
+
placement: "button",
|
|
46
|
+
Component: OidcSignInButton,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default oidcAuthExtension;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useOidcSignIn } from "./use-oidc-sign-in";
|