forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice-auth.ts
More file actions
39 lines (36 loc) · 874 Bytes
/
Copy pathdevice-auth.ts
File metadata and controls
39 lines (36 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
export type DeviceAuthEntry = {
token: string;
role: string;
scopes: string[];
updatedAtMs: number;
};
export type DeviceAuthStore = {
version: 1;
deviceId: string;
tokens: Record<string, DeviceAuthEntry>;
};
export function normalizeDeviceAuthRole(role: string): string {
return role.trim();
}
export function normalizeDeviceAuthScopes(scopes: readonly unknown[] | undefined): string[] {
if (!Array.isArray(scopes)) {
return [];
}
const out = new Set<string>();
for (const scope of scopes) {
if (typeof scope !== "string") {
continue;
}
const trimmed = scope.trim();
if (trimmed) {
out.add(trimmed);
}
}
if (out.has("operator.admin")) {
out.add("operator.read");
out.add("operator.write");
} else if (out.has("operator.write")) {
out.add("operator.read");
}
return [...out].toSorted();
}