mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
a06671e8ce
This PR contains the necessary work to make Outline an OAuth provider including: - OAuth app registration - OAuth app management - Private / public apps (Public in cloud only) - Full OAuth 2.0 spec compatible authentication flow - Granular scopes - User token management screen in settings - Associated API endpoints for programatic access
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import type { TFunction } from "i18next";
|
|
import capitalize from "lodash/capitalize";
|
|
import uniq from "lodash/uniq";
|
|
import { Scope } from "@shared/types";
|
|
|
|
export class OAuthScopeHelper {
|
|
public static normalizeScopes(scopes: string[], t: TFunction): string[] {
|
|
const methodToReadable = {
|
|
list: t("read"),
|
|
info: t("read"),
|
|
read: t("read"),
|
|
write: t("write"),
|
|
create: t("write"),
|
|
update: t("write"),
|
|
delete: t("write"),
|
|
"*": t("read and write"),
|
|
};
|
|
|
|
const translatedNamespaces = {
|
|
apiKeys: t("API keys"),
|
|
attachments: t("attachments"),
|
|
collections: t("collections"),
|
|
comments: t("comments"),
|
|
documents: t("documents"),
|
|
events: t("events"),
|
|
groups: t("groups"),
|
|
integrations: t("integrations"),
|
|
notifications: t("notifications"),
|
|
reactions: t("reactions"),
|
|
pins: t("pins"),
|
|
shares: t("shares"),
|
|
users: t("users"),
|
|
teams: t("teams"),
|
|
"*": t("workspace"),
|
|
};
|
|
|
|
const normalizedScopes = scopes.map((scope) => {
|
|
if (scope === Scope.Read) {
|
|
return t("Read all data");
|
|
}
|
|
if (scope === Scope.Write) {
|
|
return t("Write all data");
|
|
}
|
|
|
|
const [namespace, method] = scope.replace("/api/", "").split(/[:\.]/g);
|
|
const readableMethod =
|
|
methodToReadable[method as keyof typeof methodToReadable] ?? method;
|
|
const translatedNamespace =
|
|
translatedNamespaces[namespace as keyof typeof translatedNamespaces] ??
|
|
namespace;
|
|
return capitalize(`${readableMethod} ${translatedNamespace}`);
|
|
});
|
|
|
|
return uniq(normalizedScopes);
|
|
}
|
|
}
|