Skip to content

Commit bf124da

Browse files
committed
add passkey
1 parent 1d65c21 commit bf124da

File tree

5 files changed

+99
-11
lines changed

5 files changed

+99
-11
lines changed

dev-demo/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import apiKeysResource from './resources/api_keys.js';
1818
import CompletionAdapterOpenAIChatGPT from '../adapters/adminforth-completion-adapter-open-ai-chat-gpt/index.js';
1919
import pkg from 'pg';
2020
import I18nPlugin from '../plugins/adminforth-i18n/index.js';
21+
import passkeysResource from './resources/passkeys.js';
22+
2123
const { Client } = pkg;
2224

2325

@@ -215,6 +217,7 @@ export const admin = new AdminForth({
215217
},
216218
],
217219
resources: [
220+
passkeysResource,
218221
clicksResource,
219222
auditLogResource,
220223
apartmentsResource,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- CreateTable
2+
CREATE TABLE "passkeys" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"credential_id" TEXT NOT NULL,
5+
"user_id" TEXT NOT NULL,
6+
"meta" TEXT NOT NULL
7+
);
8+
9+
-- CreateIndex
10+
CREATE INDEX "passkeys_user_id_idx" ON "passkeys"("user_id");
11+
12+
-- CreateIndex
13+
CREATE INDEX "passkeys_credential_id_idx" ON "passkeys"("credential_id");

dev-demo/resources/passkeys.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { AdminForthDataTypes, AdminForthResourceInput } from "../../adminforth";
2+
import { randomUUID } from "crypto";
3+
4+
export default {
5+
dataSource: 'maindb',
6+
table: 'passkeys',
7+
resourceId: 'passkeys',
8+
label: 'Passkeys',
9+
columns: [
10+
{
11+
name: 'id',
12+
label: 'ID',
13+
primaryKey: true,
14+
showIn: { all: false},
15+
fillOnCreate: () => randomUUID(),
16+
},
17+
{
18+
name: 'credential_id',
19+
label: 'Credential ID',
20+
},
21+
{
22+
name: 'user_id',
23+
label: 'User ID',
24+
},
25+
{
26+
name: "meta",
27+
type: AdminForthDataTypes.JSON,
28+
label: "Meta",
29+
}
30+
],
31+
plugins: [],
32+
options: {},
33+
} as AdminForthResourceInput;

dev-demo/resources/users.ts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,47 @@ export default {
7474
twoFaSecretFieldName: "secret2fa",
7575
timeStepWindow: 1, // optional time step window for 2FA
7676
// optional callback to define which users should be enforced to use 2FA
77-
usersFilterToApply: (adminUser: AdminUser) => {
78-
if (process.env.NODE_ENV === "development") {
79-
return false;
80-
}
81-
// return true if user should be enforced to use 2FA,
82-
// return true;
83-
return adminUser.dbUser.email !== "adminforth";
84-
},
85-
usersFilterToAllowSkipSetup: (adminUser: AdminUser) => {
86-
return adminUser.dbUser.email === "adminforth";
87-
},
77+
// usersFilterToApply: (adminUser: AdminUser) => {
78+
// if (process.env.NODE_ENV === "development") {
79+
// return false;
80+
// }
81+
// // return true if user should be enforced to use 2FA,
82+
// // return true;
83+
// return adminUser.dbUser.email !== "adminforth";
84+
// },
85+
// usersFilterToAllowSkipSetup: (adminUser: AdminUser) => {
86+
// return adminUser.dbUser.email === "adminforth";
87+
// },
88+
passkeys: {
89+
credentialResourceID: "passkeys",
90+
credentialIdFieldName: "credential_id",
91+
credentialMetaFieldName: "meta",
92+
credentialUserIdFieldName: "user_id",
93+
settings: {
94+
expectedOrigin: "http://localhost:3000", // important, set it to your backoffice origin (starts from scheme, no slash at the end)
95+
// relying party config
96+
rp: {
97+
name: "New Reality",
98+
99+
// optionaly you can set expected id explicitly if you need to:
100+
// id: "localhost",
101+
},
102+
user: {
103+
nameField: "email",
104+
displayNameField: "email",
105+
},
106+
authenticatorSelection: {
107+
// impacts a way how passkey will be created
108+
// - platform - using browser internal authenticator (e.g. Google Chrome passkey / Google Password Manager )
109+
// - cross-platform - using external authenticator (e.g. Yubikey, Google Titan etc)
110+
// - both - plging will show both options to the user
111+
// Can be "platform", "cross-platform" or "both"
112+
authenticatorAttachment: "both",
113+
requireResidentKey: true,
114+
userVerification: "required",
115+
},
116+
},
117+
}
88118
}),
89119
...(process.env.AWS_ACCESS_KEY_ID
90120
? [

dev-demo/schema.prisma

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,13 @@ model api_keys {
125125
name String
126126
owner String?
127127
owner_id String?
128+
}
129+
130+
model passkeys {
131+
id String @id
132+
credential_id String
133+
user_id String
134+
meta String
135+
@@index([user_id])
136+
@@index([credential_id])
128137
}

0 commit comments

Comments
 (0)