mirror of
https://github.com/Sevichecc/m-oauth.git
synced 2025-04-30 06:59:29 +08:00
style: add comments
This commit is contained in:
parent
5a87613452
commit
c418934e7a
2 changed files with 129 additions and 59 deletions
186
lib/scopes.ts
186
lib/scopes.ts
|
@ -1,6 +1,8 @@
|
||||||
import { ScopeInfo } from "./types";
|
import { ScopeInfo } from "./types";
|
||||||
|
import { InstanceType } from "./types";
|
||||||
|
|
||||||
export const READ_SCOPES = [
|
// Mastodon Scopes
|
||||||
|
const READ_SCOPES = [
|
||||||
"read:accounts",
|
"read:accounts",
|
||||||
"read:blocks",
|
"read:blocks",
|
||||||
"read:bookmarks",
|
"read:bookmarks",
|
||||||
|
@ -14,7 +16,7 @@ export const READ_SCOPES = [
|
||||||
"read:statuses",
|
"read:statuses",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const WRITE_SCOPES = [
|
const WRITE_SCOPES = [
|
||||||
"write:account",
|
"write:account",
|
||||||
"write:blocks",
|
"write:blocks",
|
||||||
"write:bookmarks",
|
"write:bookmarks",
|
||||||
|
@ -29,7 +31,7 @@ export const WRITE_SCOPES = [
|
||||||
"write:reports",
|
"write:reports",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ADMIN_READ_SCOPES = [
|
const ADMIN_READ_SCOPES = [
|
||||||
"admin:read",
|
"admin:read",
|
||||||
"admin:read:account",
|
"admin:read:account",
|
||||||
"admin:read:reports",
|
"admin:read:reports",
|
||||||
|
@ -40,7 +42,7 @@ export const ADMIN_READ_SCOPES = [
|
||||||
"admin:read:canonical_email_blocks",
|
"admin:read:canonical_email_blocks",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ADMIN_WRITE_SCOPES = [
|
const ADMIN_WRITE_SCOPES = [
|
||||||
"admin:write",
|
"admin:write",
|
||||||
"admin:write:account",
|
"admin:write:account",
|
||||||
"admin:write:reports",
|
"admin:write:reports",
|
||||||
|
@ -51,33 +53,17 @@ export const ADMIN_WRITE_SCOPES = [
|
||||||
"admin:write:canonical_email_blocks",
|
"admin:write:canonical_email_blocks",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const PLEROMA_READ_SCOPE = [
|
// Pleroma Scopes
|
||||||
|
const PLEROMA_READ_SCOPE = [
|
||||||
...READ_SCOPES,
|
...READ_SCOPES,
|
||||||
"read:backups",
|
"read:backups",
|
||||||
"read:chats",
|
"read:chats",
|
||||||
"read:securit",
|
"read:securit",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const PLEROMA_WRITE_SCOPE = [
|
const PLEROMA_WRITE_SCOPE = [...WRITE_SCOPES, "write:chats", "write:security"];
|
||||||
...WRITE_SCOPES,
|
|
||||||
"write:chats",
|
|
||||||
"write:security",
|
|
||||||
];
|
|
||||||
|
|
||||||
export const AKKOMA_READ_SCOPE = [
|
const PLEROMA_ADMIN_READ_SCOPES = [
|
||||||
...READ_SCOPES,
|
|
||||||
"read:backups",
|
|
||||||
"read:chats",
|
|
||||||
"read:securit",
|
|
||||||
];
|
|
||||||
|
|
||||||
export const AKKOMA_WRITE_SCOPE = [
|
|
||||||
...WRITE_SCOPES,
|
|
||||||
"write:chats",
|
|
||||||
"write:security",
|
|
||||||
];
|
|
||||||
|
|
||||||
export const PLEROMA_ADMIN_READ_SCOPES = [
|
|
||||||
...ADMIN_READ_SCOPES,
|
...ADMIN_READ_SCOPES,
|
||||||
"admin:read:chats",
|
"admin:read:chats",
|
||||||
"admin:read:invites",
|
"admin:read:invites",
|
||||||
|
@ -85,7 +71,7 @@ export const PLEROMA_ADMIN_READ_SCOPES = [
|
||||||
"admin:read:follows",
|
"admin:read:follows",
|
||||||
"admin:read:media_proxy_caches",
|
"admin:read:media_proxy_caches",
|
||||||
];
|
];
|
||||||
export const PLEROMA_ADMIN_WRITE_SCOPES = [
|
const PLEROMA_ADMIN_WRITE_SCOPES = [
|
||||||
...ADMIN_READ_SCOPES,
|
...ADMIN_READ_SCOPES,
|
||||||
"admin:write:chats",
|
"admin:write:chats",
|
||||||
"admin:write:invites",
|
"admin:write:invites",
|
||||||
|
@ -94,39 +80,121 @@ export const PLEROMA_ADMIN_WRITE_SCOPES = [
|
||||||
"admin:write:media_proxy_caches",
|
"admin:write:media_proxy_caches",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const scopesInfo: ScopeInfo[] = [
|
// Akkoma Scopes
|
||||||
{
|
const AKKOMA_READ_SCOPE = PLEROMA_WRITE_SCOPE.filter(
|
||||||
method: "read",
|
(scope) => scope !== "read:chats"
|
||||||
label: "Read",
|
);
|
||||||
scopes: READ_SCOPES,
|
const AKKOMA_WRITE_SCOPE = PLEROMA_WRITE_SCOPE.filter(
|
||||||
description: "read account's data",
|
(scope) => scope !== "write:chats"
|
||||||
},
|
);
|
||||||
{
|
const AKKOMA_ADMIN_READ_SCOPES = PLEROMA_ADMIN_READ_SCOPES.filter(
|
||||||
method: "write",
|
(scope) => scope !== "admin:read:chats"
|
||||||
label: "Write",
|
);
|
||||||
scopes: WRITE_SCOPES,
|
const AKKOMA_ADMIN_WRITE_SCOPES = PLEROMA_ADMIN_WRITE_SCOPES.filter(
|
||||||
description: "modify account's data",
|
(scope) => scope !== "admin:write:chats"
|
||||||
},
|
);
|
||||||
{
|
|
||||||
method: "admin",
|
|
||||||
label: "Admin",
|
|
||||||
scopes: [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES],
|
|
||||||
description: "read all data on the server",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "follow",
|
|
||||||
label: "Follow",
|
|
||||||
description: "modify account relationships,deprecated in 3.5.0 and newer.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "push",
|
|
||||||
label: "Push",
|
|
||||||
description: "receive push notifications",
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
// Miskky Scopes
|
||||||
method: "crypto",
|
|
||||||
label: "Crypto",
|
const MISSKEY_READ_SCOPES = [
|
||||||
description: "use end-to-end encryption",
|
"read:account",
|
||||||
},
|
"read:blocks",
|
||||||
|
"read:drive",
|
||||||
|
"read:favorites",
|
||||||
|
"read:following",
|
||||||
|
"read:messaging",
|
||||||
|
"read:mutes",
|
||||||
|
"read:notifications",
|
||||||
|
"read:reactions",
|
||||||
|
"read:pages",
|
||||||
|
"read:page-likes",
|
||||||
|
"read:user-groups",
|
||||||
|
"read:channels",
|
||||||
|
"read:gallery",
|
||||||
|
"read:gallery-likes",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const MISSKEY_WRITE_SCOPES = [
|
||||||
|
"write:account",
|
||||||
|
"write:blocks",
|
||||||
|
"write:drive",
|
||||||
|
"write:favorites",
|
||||||
|
"write:following",
|
||||||
|
"write:messaging",
|
||||||
|
"write:mutes",
|
||||||
|
"write:notes",
|
||||||
|
"write:notifications",
|
||||||
|
"write:reactions",
|
||||||
|
"write:votes",
|
||||||
|
"write:pages",
|
||||||
|
"write:page-likes",
|
||||||
|
"write:user-groups",
|
||||||
|
"write:channels",
|
||||||
|
"write:gallery",
|
||||||
|
"write:gallery-likes",
|
||||||
|
'write:clip-favorite',
|
||||||
|
'write:flash'
|
||||||
|
];
|
||||||
|
|
||||||
|
export const getScopes = (instanceType: InstanceType): ScopeInfo[] => {
|
||||||
|
let readScopes = READ_SCOPES;
|
||||||
|
let writeScopes = WRITE_SCOPES;
|
||||||
|
let adminScopes = [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES];
|
||||||
|
|
||||||
|
switch (instanceType) {
|
||||||
|
case "mastodon":
|
||||||
|
break;
|
||||||
|
case "akkoma":
|
||||||
|
readScopes = AKKOMA_READ_SCOPE;
|
||||||
|
writeScopes = AKKOMA_WRITE_SCOPE;
|
||||||
|
adminScopes = [AKKOMA_ADMIN_READ_SCOPES, AKKOMA_ADMIN_WRITE_SCOPES];
|
||||||
|
break;
|
||||||
|
case "pleroma":
|
||||||
|
readScopes = PLEROMA_READ_SCOPE;
|
||||||
|
writeScopes = PLEROMA_WRITE_SCOPE;
|
||||||
|
adminScopes = [PLEROMA_ADMIN_READ_SCOPES, PLEROMA_ADMIN_WRITE_SCOPES];
|
||||||
|
break;
|
||||||
|
case "misskey":
|
||||||
|
readScopes = MISSKEY_READ_SCOPES;
|
||||||
|
writeScopes = MISSKEY_WRITE_SCOPES;
|
||||||
|
adminScopes = []
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
method: "read",
|
||||||
|
label: "Read",
|
||||||
|
scopes: readScopes,
|
||||||
|
description: "read account's data",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: "write",
|
||||||
|
label: "Write",
|
||||||
|
scopes: writeScopes,
|
||||||
|
description: "modify account's data",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: "admin",
|
||||||
|
label: "Admin",
|
||||||
|
scopes: adminScopes,
|
||||||
|
description: "read all data on the server",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: "follow",
|
||||||
|
label: "Follow",
|
||||||
|
description:
|
||||||
|
"modify account relationships,deprecated in 3.5.0 and newer.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: "push",
|
||||||
|
label: "Push",
|
||||||
|
description: "receive push notifications",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
method: "crypto",
|
||||||
|
label: "Crypto",
|
||||||
|
description: "use end-to-end encryption",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
export type InstanceType = "mastodon" | "akkoma" | "misskey" | "pleroma";
|
||||||
|
|
||||||
export type MethodType =
|
export type MethodType =
|
||||||
| "read"
|
| "read"
|
||||||
| "write"
|
| "write"
|
||||||
|
|
Loading…
Reference in a new issue