@springmicro/auth 0.3.0 → 0.3.5
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/.eslintrc.cjs +0 -0
- package/README.md +60 -60
- package/dist/{Index-c419311f-DolmVisI.js → Index-64ac63ff-mcEPPGzJ.js} +101 -102
- package/dist/{Index-652aeb8c-Cr1mbyJJ.js → Index-6c094240-D4xpr8fA.js} +70 -71
- package/dist/{Web3Auth-C5tucK1E.js → Web3Auth-DB9s-qbl.js} +12454 -12511
- package/dist/alphawallet-B7eovdf-.js +0 -0
- package/dist/apexwallet-ysP20G9D.js +0 -0
- package/dist/atoken-BBnNTzcz.js +0 -0
- package/dist/bifrostwallet-CNNBO92h.js +0 -0
- package/dist/binance-DvPgAzCw.js +0 -0
- package/dist/bitget-DZOUrwgy.js +0 -0
- package/dist/bitpie-C_uxmEzw.js +0 -0
- package/dist/bitski-DpzkHNkv.js +0 -0
- package/dist/blockwallet-BL69cqkA.js +0 -0
- package/dist/brave-DnRzMQYW.js +0 -0
- package/dist/ccip-c78d2f16-DLcRlwod.js +0 -0
- package/dist/coin98wallet-CkFdOvXt.js +0 -0
- package/dist/coinbase-CaGNx5if.js +0 -0
- package/dist/core-9rK8tWud.js +0 -0
- package/dist/defiwallet-0AsgJBSy.js +0 -0
- package/dist/detected-CX_JZaUk.js +0 -0
- package/dist/echooo-CmaetT_Z.js +0 -0
- package/dist/enkrypt-BibtwvK7.js +0 -0
- package/dist/exodus-BxzkDWWP.js +0 -0
- package/dist/fordefi-CvKyVwhI.js +0 -0
- package/dist/foxwallet-D7c_LDTf.js +0 -0
- package/dist/frame-CDfNmjUy.js +0 -0
- package/dist/frontier-DqKNSj2z.js +0 -0
- package/dist/hashMessage-Dw0KdqMZ.js +2101 -0
- package/dist/huobiwallet-CxSwqa5L.js +0 -0
- package/dist/hyperpay-nmHE3WqM.js +0 -0
- package/dist/icon-2Zqy7pqQ.js +0 -0
- package/dist/icon-CGWI1Ies.js +0 -0
- package/dist/icon-C_O4nprO.js +0 -0
- package/dist/icon-DbgmZCnU.js +0 -0
- package/dist/icon-Dbjb6jc5.js +20 -0
- package/dist/icon-cAd7RhSC.js +0 -0
- package/dist/imtoken-yENtOTS3.js +0 -0
- package/dist/index-021f6a62-Zz543EDB.js +0 -0
- package/dist/index-40a497ea-Bn2mC0r7.js +0 -0
- package/dist/{index-YKlm7xSx.js → index-C0yeApwY.js} +750 -751
- package/dist/{index-C4uVsW-I.js → index-CDaoza_m.js} +2 -2
- package/dist/index-CiwBcaZ0.js +384 -0
- package/dist/{index-DOUI-2vv.js → index-CroNOC7e.js} +27 -29
- package/dist/{index-Boi-WcMK.js → index-Df5ie3cE.js} +2 -2
- package/dist/{index-DzOmdGpF.js → index-F-gl3DJX.js} +8 -10
- package/dist/index-wNV8PBAh.js +11412 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +327 -291
- package/dist/infinitywallet-C8J4FUYw.js +0 -0
- package/dist/kayros-AIrUK1za.js +0 -0
- package/dist/keplr-CyLTca9B.js +36 -0
- package/dist/lif3wallet-C5D6r8pg.js +0 -0
- package/dist/liquality-nbCtErVq.js +0 -0
- package/dist/mathwallet-CWkivCXo.js +0 -0
- package/dist/meetone-kKmvI8md.js +0 -0
- package/dist/metamask-BN7yiDV1.js +0 -0
- package/dist/mykey-CQZ6UcLH.js +0 -0
- package/dist/native-FDN9oNjc.js +15 -0
- package/dist/{number-UhidYs-H.js → number-ByqdQYDu.js} +1 -1
- package/dist/okxwallet-CJLVogh2.js +0 -0
- package/dist/oneInch-CciyZ4Pz.js +0 -0
- package/dist/onekey-Dal8kYjU.js +0 -0
- package/dist/opera-DnKg-TJU.js +0 -0
- package/dist/ownbit-BshJUVuW.js +0 -0
- package/dist/phantom-CJ8dIcov.js +0 -0
- package/dist/rabby-D4thTcd6.js +0 -0
- package/dist/rainbow-mXld6yWV.js +0 -0
- package/dist/roninwallet-ZyYrd-D1.js +0 -0
- package/dist/safeheron-Eg1Jb29V.js +0 -0
- package/dist/safepal-DVIKy94N.js +0 -0
- package/dist/sequence-BS2IbtDg.js +0 -0
- package/dist/stablewallet-jyB079Wb.js +0 -0
- package/dist/status-FrAvQjfn.js +0 -0
- package/dist/subwallet-DMvFqKyY.js +0 -0
- package/dist/talisman-Bp8zUXqB.js +0 -0
- package/dist/tallywallet-B4OS9nIr.js +0 -0
- package/dist/tokenary-C7jjcbQa.js +0 -0
- package/dist/tokenpocket-9ZRPmAFA.js +0 -0
- package/dist/tp-V2em5bdl.js +0 -0
- package/dist/transactionRequest-be6a8ea9-CUKWo5mx.js +0 -0
- package/dist/trust-SgHubMq7.js +20 -0
- package/dist/xdefi-COVIyGz4.js +0 -0
- package/dist/zeal-DxHbDqm0.js +0 -0
- package/dist/zerion-BfW0UElc.js +0 -0
- package/dist/zodiacpilot-CrId6F4w.js +0 -0
- package/index.html +0 -0
- package/package.json +2 -2
- package/src/auth/config.ts +91 -91
- package/src/components/SignUp.tsx +442 -442
- package/src/components/forms/AgreementModal.tsx +88 -88
- package/src/components/forms/CaptchaController.tsx +94 -94
- package/src/components/forms/CaptchaModal.jsx +171 -171
- package/src/components/forms/CaptchaWidget.jsx +146 -146
- package/src/components/forms/PasswordChecker.ts +88 -88
- package/src/components/forms/SendCodeInput.tsx +149 -149
- package/src/components/forms/SignUpFormItem.tsx +704 -704
- package/src/components/forms/util/application-api.ts +155 -155
- package/src/components/forms/util/auth-api.ts +198 -198
- package/src/components/forms/util/auth-util.tsx +346 -346
- package/src/components/forms/util/core.ts +493 -493
- package/src/components/forms/util/invitation-api.ts +132 -132
- package/src/components/forms/util/provider.tsx +603 -603
- package/src/components/forms/util/user-api.ts +303 -303
- package/src/components/provider/AdfsLoginButton.jsx +38 -38
- package/src/components/provider/AlipayLoginButton.jsx +38 -38
- package/src/components/provider/AppleLoginButton.jsx +38 -38
- package/src/components/provider/AzureADB2CLoginButton.jsx +38 -38
- package/src/components/provider/AzureADLoginButton.jsx +38 -38
- package/src/components/provider/BaiduLoginButton.jsx +38 -38
- package/src/components/provider/BilibiliLoginButton.jsx +37 -37
- package/src/components/provider/CasdoorLoginButton.jsx +38 -38
- package/src/components/provider/DingTalkLoginButton.jsx +37 -37
- package/src/components/provider/DouyinLoginButton.jsx +38 -38
- package/src/components/provider/FacebookLoginButton.jsx +37 -37
- package/src/components/provider/GitHubLoginButton.jsx +37 -37
- package/src/components/provider/GitLabLoginButton.jsx +38 -38
- package/src/components/provider/GiteeLoginButton.jsx +34 -34
- package/src/components/provider/GoogleLoginButton.jsx +68 -68
- package/src/components/provider/InfoflowLoginButton.jsx +38 -38
- package/src/components/provider/LarkLoginButton.jsx +38 -38
- package/src/components/provider/LinkedInLoginButton.jsx +37 -37
- package/src/components/provider/LoginButton.jsx +33 -33
- package/src/components/provider/OktaLoginButton.jsx +38 -38
- package/src/components/provider/Provider.jsx +3 -3
- package/src/components/provider/ProviderButton.jsx +327 -327
- package/src/components/provider/QqLoginButton.jsx +31 -31
- package/src/components/provider/SelfLoginButton.jsx +47 -47
- package/src/components/provider/SlackLoginButton.jsx +38 -38
- package/src/components/provider/SteamLoginButton.jsx +38 -38
- package/src/components/provider/WeComLoginButton.jsx +34 -34
- package/src/components/provider/Web3Auth.jsx +365 -365
- package/src/components/provider/WechatLoginButton.jsx +37 -37
- package/src/components/provider/WeiboLoginButton.jsx +34 -34
- package/src/components/util.tsx +173 -173
- package/src/i18n/en/signup.json +48 -48
- package/src/i18n/index.ts +17 -17
- package/src/index.tsx +8 -8
- package/src/vite-env.d.ts +0 -0
- package/tsconfig.json +0 -0
- package/tsconfig.node.json +0 -0
- package/vite.config.ts +33 -33
- package/dist/icon-duCa3gfT.js +0 -11
- package/dist/index-BtLU53lm.js +0 -6023
- package/dist/index-CLfsMiG4.js +0 -2021
- package/dist/index-DPq81SIn.js +0 -161
- package/dist/trust-gPypS1O7.js +0 -11
|
File without changes
|
package/dist/kayros-AIrUK1za.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const t = `
|
|
2
|
+
<svg width="42" height="42" viewBox="0 0 42 42" fill="none"
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg">
|
|
4
|
+
<g clip-path="url(#clip0_425_5107)">
|
|
5
|
+
<path d="M32.4545 0H9.54545C4.27365 0 0 4.27365 0 9.54545V32.4545C0 37.7264 4.27365 42 9.54545 42H32.4545C37.7264 42 42 37.7264 42 32.4545V9.54545C42 4.27365 37.7264 0 32.4545 0Z" fill="url(#paint0_linear_425_5107)"/>
|
|
6
|
+
<path d="M32.4545 0H9.54545C4.27365 0 0 4.27365 0 9.54545V32.4545C0 37.7264 4.27365 42 9.54545 42H32.4545C37.7264 42 42 37.7264 42 32.4545V9.54545C42 4.27365 37.7264 0 32.4545 0Z" fill="url(#paint1_radial_425_5107)"/>
|
|
7
|
+
<path d="M32.4545 0H9.54545C4.27365 0 0 4.27365 0 9.54545V32.4545C0 37.7264 4.27365 42 9.54545 42H32.4545C37.7264 42 42 37.7264 42 32.4545V9.54545C42 4.27365 37.7264 0 32.4545 0Z" fill="url(#paint2_radial_425_5107)"/>
|
|
8
|
+
<path d="M32.4545 0H9.54545C4.27365 0 0 4.27365 0 9.54545V32.4545C0 37.7264 4.27365 42 9.54545 42H32.4545C37.7264 42 42 37.7264 42 32.4545V9.54545C42 4.27365 37.7264 0 32.4545 0Z" fill="url(#paint3_radial_425_5107)"/>
|
|
9
|
+
<path d="M17.2526 32.2614V22.5192L26.7185 32.2614H31.9849V32.0079L21.0964 20.9122L31.1469 10.3857V10.2614H25.8464L17.2526 19.5635V10.2614H12.9849V32.2614H17.2526Z" fill="white"/>
|
|
10
|
+
</g>
|
|
11
|
+
<defs>
|
|
12
|
+
<linearGradient id="paint0_linear_425_5107" x1="21" y1="0" x2="21" y2="42" gradientUnits="userSpaceOnUse">
|
|
13
|
+
<stop stop-color="#1FD1FF"/>
|
|
14
|
+
<stop offset="1" stop-color="#1BB8FF"/>
|
|
15
|
+
</linearGradient>
|
|
16
|
+
<radialGradient id="paint1_radial_425_5107" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(2.00623 40.4086) rotate(-45.1556) scale(67.3547 68.3624)">
|
|
17
|
+
<stop stop-color="#232DE3"/>
|
|
18
|
+
<stop offset="1" stop-color="#232DE3" stop-opacity="0"/>
|
|
19
|
+
</radialGradient>
|
|
20
|
+
<radialGradient id="paint2_radial_425_5107" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(39.7379 41.7602) rotate(-138.45) scale(42.1137 64.2116)">
|
|
21
|
+
<stop stop-color="#8B4DFF"/>
|
|
22
|
+
<stop offset="1" stop-color="#8B4DFF" stop-opacity="0"/>
|
|
23
|
+
</radialGradient>
|
|
24
|
+
<radialGradient id="paint3_radial_425_5107" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(20.6501 0.311498) rotate(90) scale(33.1135 80.3423)">
|
|
25
|
+
<stop stop-color="#24D5FF"/>
|
|
26
|
+
<stop offset="1" stop-color="#1BB8FF" stop-opacity="0"/>
|
|
27
|
+
</radialGradient>
|
|
28
|
+
<clipPath id="clip0_425_5107">
|
|
29
|
+
<rect width="42" height="42" fill="white"/>
|
|
30
|
+
</clipPath>
|
|
31
|
+
</defs>
|
|
32
|
+
</svg>
|
|
33
|
+
`;
|
|
34
|
+
export {
|
|
35
|
+
t as default
|
|
36
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/meetone-kKmvI8md.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/mykey-CQZ6UcLH.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function e() {
|
|
2
|
+
if (typeof WebSocket < "u")
|
|
3
|
+
return WebSocket;
|
|
4
|
+
if (typeof global.WebSocket < "u")
|
|
5
|
+
return global.WebSocket;
|
|
6
|
+
if (typeof window.WebSocket < "u")
|
|
7
|
+
return window.WebSocket;
|
|
8
|
+
if (typeof self.WebSocket < "u")
|
|
9
|
+
return self.WebSocket;
|
|
10
|
+
throw new Error("`WebSocket` is not supported in this environment");
|
|
11
|
+
}
|
|
12
|
+
const t = e();
|
|
13
|
+
export {
|
|
14
|
+
t as WebSocket
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as D, t as ue, q as h, B as f, o as He, s as I, y as ce, C as ze, u as je, d as P, n as w, f as $, g as U, e as te } from "./Web3Auth-
|
|
1
|
+
import { i as D, t as ue, q as h, B as f, o as He, s as I, y as ce, C as ze, u as je, d as P, n as w, f as $, g as U, e as te } from "./Web3Auth-DB9s-qbl.js";
|
|
2
2
|
function A(e) {
|
|
3
3
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
4
4
|
throw new Error(`Wrong positive integer: ${e}`);
|
|
File without changes
|
package/dist/oneInch-CciyZ4Pz.js
CHANGED
|
File without changes
|
package/dist/onekey-Dal8kYjU.js
CHANGED
|
File without changes
|
package/dist/opera-DnKg-TJU.js
CHANGED
|
File without changes
|
package/dist/ownbit-BshJUVuW.js
CHANGED
|
File without changes
|
package/dist/phantom-CJ8dIcov.js
CHANGED
|
File without changes
|
package/dist/rabby-D4thTcd6.js
CHANGED
|
File without changes
|
package/dist/rainbow-mXld6yWV.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/safepal-DVIKy94N.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/status-FrAvQjfn.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/tp-V2em5bdl.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const t = `
|
|
2
|
+
<svg width="39" height="43" viewBox="0 0 39 43" fill="none"
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg" exponent="92384" class="mt-4 h-auto w-[180px]">
|
|
4
|
+
<path d="M0.710815 6.67346L19.4317 0.606445V42.6064C6.05944 37.0059 0.710815 26.2727 0.710815 20.207V6.67346Z" fill="#0500FF"></path>
|
|
5
|
+
<path d="M38.1537 6.67346L19.4329 0.606445V42.6064C32.8051 37.0059 38.1537 26.2727 38.1537 20.207V6.67346Z" fill="url(#paint0_linear_524_7586892384)"></path>
|
|
6
|
+
<defs>
|
|
7
|
+
<linearGradient id="paint0_linear_524_7586892384" x1="33.1809" y1="-2.33467" x2="19.115" y2="42.0564" gradientUnits="userSpaceOnUse">
|
|
8
|
+
<stop offset="0.02" stop-color="#0000FF"></stop>
|
|
9
|
+
<stop offset="0.08" stop-color="#0094FF"></stop>
|
|
10
|
+
<stop offset="0.16" stop-color="#48FF91"></stop>
|
|
11
|
+
<stop offset="0.42" stop-color="#0094FF"></stop>
|
|
12
|
+
<stop offset="0.68" stop-color="#0038FF"></stop>
|
|
13
|
+
<stop offset="0.9" stop-color="#0500FF"></stop>
|
|
14
|
+
</linearGradient>
|
|
15
|
+
</defs>
|
|
16
|
+
</svg>
|
|
17
|
+
`;
|
|
18
|
+
export {
|
|
19
|
+
t as default
|
|
20
|
+
};
|
package/dist/xdefi-COVIyGz4.js
CHANGED
|
File without changes
|
package/dist/zeal-DxHbDqm0.js
CHANGED
|
File without changes
|
package/dist/zerion-BfW0UElc.js
CHANGED
|
File without changes
|
|
File without changes
|
package/index.html
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@springmicro/auth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"react-social-login-buttons": "^4.1.0",
|
|
55
55
|
"uuid": "^9.0.1"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "1bbf206d79047e5897172fb794fc876ad6c45498"
|
|
58
58
|
}
|
package/src/auth/config.ts
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import { defineConfig } from "auth-astro";
|
|
2
|
-
|
|
3
|
-
type UserProfile = {
|
|
4
|
-
id: string;
|
|
5
|
-
displayName: string;
|
|
6
|
-
email: string;
|
|
7
|
-
avatar: string;
|
|
8
|
-
name: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type NextAuthJWT = {
|
|
12
|
-
token: any;
|
|
13
|
-
account: any | null;
|
|
14
|
-
user: any;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type NextAuthSession = {
|
|
18
|
-
session: any;
|
|
19
|
-
token: any;
|
|
20
|
-
user: any;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// https://authjs.dev/guides/configuring-oauth-providers#use-your-own-provider
|
|
24
|
-
type AuthConfig = {
|
|
25
|
-
casdoorEndpoint: string;
|
|
26
|
-
clientId: string;
|
|
27
|
-
clientSecret: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @param param0 {
|
|
32
|
-
casdoorEndpoint: http://casdoor.tld;
|
|
33
|
-
clientId: hex;
|
|
34
|
-
clientSecret: hex;
|
|
35
|
-
}
|
|
36
|
-
* @returns FullAuthConfig
|
|
37
|
-
*/
|
|
38
|
-
const getAuthConfig = ({
|
|
39
|
-
casdoorEndpoint,
|
|
40
|
-
clientId,
|
|
41
|
-
clientSecret,
|
|
42
|
-
}: AuthConfig) =>
|
|
43
|
-
defineConfig({
|
|
44
|
-
// Configure one or more authentication providers
|
|
45
|
-
providers: [
|
|
46
|
-
{
|
|
47
|
-
id: "casdoor",
|
|
48
|
-
name: "SpringMicroHost",
|
|
49
|
-
type: "oidc",
|
|
50
|
-
issuer: casdoorEndpoint,
|
|
51
|
-
authorization: { params: { scope: "openid email profile" } },
|
|
52
|
-
token: true,
|
|
53
|
-
checks: ["state"],
|
|
54
|
-
clientId: clientId,
|
|
55
|
-
clientSecret: clientSecret,
|
|
56
|
-
profile(profile: UserProfile) {
|
|
57
|
-
return {
|
|
58
|
-
id: profile.id,
|
|
59
|
-
name: profile.displayName,
|
|
60
|
-
email: profile.email,
|
|
61
|
-
username: profile.name ?? profile.email,
|
|
62
|
-
image: profile.avatar,
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
pages: {
|
|
68
|
-
signIn: "/sign-in",
|
|
69
|
-
},
|
|
70
|
-
callbacks: {
|
|
71
|
-
async jwt({ token, account, user }: NextAuthJWT) {
|
|
72
|
-
// Persist the OAuth access_token and or the user id to the token right after signin
|
|
73
|
-
if (account) {
|
|
74
|
-
token.accessToken = account.access_token ?? "";
|
|
75
|
-
token.username = user.username;
|
|
76
|
-
token.id = user.id;
|
|
77
|
-
}
|
|
78
|
-
return token;
|
|
79
|
-
},
|
|
80
|
-
async session({ session, token, user }: NextAuthSession) {
|
|
81
|
-
// Send properties to the client, like an access_token and user id from a provider.
|
|
82
|
-
session.accessToken = token.accessToken;
|
|
83
|
-
session.user.id = token.id;
|
|
84
|
-
session.user.username = token.username;
|
|
85
|
-
// console.log(user, token, session);
|
|
86
|
-
return session;
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export default getAuthConfig;
|
|
1
|
+
import { defineConfig } from "auth-astro";
|
|
2
|
+
|
|
3
|
+
type UserProfile = {
|
|
4
|
+
id: string;
|
|
5
|
+
displayName: string;
|
|
6
|
+
email: string;
|
|
7
|
+
avatar: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type NextAuthJWT = {
|
|
12
|
+
token: any;
|
|
13
|
+
account: any | null;
|
|
14
|
+
user: any;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type NextAuthSession = {
|
|
18
|
+
session: any;
|
|
19
|
+
token: any;
|
|
20
|
+
user: any;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// https://authjs.dev/guides/configuring-oauth-providers#use-your-own-provider
|
|
24
|
+
type AuthConfig = {
|
|
25
|
+
casdoorEndpoint: string;
|
|
26
|
+
clientId: string;
|
|
27
|
+
clientSecret: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param param0 {
|
|
32
|
+
casdoorEndpoint: http://casdoor.tld;
|
|
33
|
+
clientId: hex;
|
|
34
|
+
clientSecret: hex;
|
|
35
|
+
}
|
|
36
|
+
* @returns FullAuthConfig
|
|
37
|
+
*/
|
|
38
|
+
const getAuthConfig = ({
|
|
39
|
+
casdoorEndpoint,
|
|
40
|
+
clientId,
|
|
41
|
+
clientSecret,
|
|
42
|
+
}: AuthConfig) =>
|
|
43
|
+
defineConfig({
|
|
44
|
+
// Configure one or more authentication providers
|
|
45
|
+
providers: [
|
|
46
|
+
{
|
|
47
|
+
id: "casdoor",
|
|
48
|
+
name: "SpringMicroHost",
|
|
49
|
+
type: "oidc",
|
|
50
|
+
issuer: casdoorEndpoint,
|
|
51
|
+
authorization: { params: { scope: "openid email profile" } },
|
|
52
|
+
token: true,
|
|
53
|
+
checks: ["state"],
|
|
54
|
+
clientId: clientId,
|
|
55
|
+
clientSecret: clientSecret,
|
|
56
|
+
profile(profile: UserProfile) {
|
|
57
|
+
return {
|
|
58
|
+
id: profile.id,
|
|
59
|
+
name: profile.displayName,
|
|
60
|
+
email: profile.email,
|
|
61
|
+
username: profile.name ?? profile.email,
|
|
62
|
+
image: profile.avatar,
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
pages: {
|
|
68
|
+
signIn: "/sign-in",
|
|
69
|
+
},
|
|
70
|
+
callbacks: {
|
|
71
|
+
async jwt({ token, account, user }: NextAuthJWT) {
|
|
72
|
+
// Persist the OAuth access_token and or the user id to the token right after signin
|
|
73
|
+
if (account) {
|
|
74
|
+
token.accessToken = account.access_token ?? "";
|
|
75
|
+
token.username = user.username;
|
|
76
|
+
token.id = user.id;
|
|
77
|
+
}
|
|
78
|
+
return token;
|
|
79
|
+
},
|
|
80
|
+
async session({ session, token, user }: NextAuthSession) {
|
|
81
|
+
// Send properties to the client, like an access_token and user id from a provider.
|
|
82
|
+
session.accessToken = token.accessToken;
|
|
83
|
+
session.user.id = token.id;
|
|
84
|
+
session.user.username = token.username;
|
|
85
|
+
// console.log(user, token, session);
|
|
86
|
+
return session;
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export default getAuthConfig;
|