diff --git a/package.json b/package.json index 20a21d3..e7b98f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lendry-erp/contracts", - "version": "1.2.37", + "version": "1.2.38", "description": "Protobuf definitions and generated TypeScript types", "type": "commonjs", "main": "./dist/index.js", diff --git a/proto/sso/auth.proto b/proto/sso/auth.proto index 0c05cc4..fec3387 100644 --- a/proto/sso/auth.proto +++ b/proto/sso/auth.proto @@ -14,9 +14,6 @@ service AuthService { rpc GetSessions(GetSessionRequest) returns (GetSessionsResponse); rpc TerminateSession(TerminateSessionRequest) returns (TerminateSessionResponse); - // === OAuth2 SSO === - rpc GenerateOauthCode (GenerateOauthCodeRequest) returns (GenerateOauthCodeResponse); - rpc ExchangeOauthCode (ExchangeOauthCodeRequest) returns (ExchangeOauthCodeResponse); // Системные методы для админа rpc SystemCreateAccount (SystemCreateAccountRequest) returns (SystemCreateAccountResponse); @@ -118,29 +115,6 @@ message TerminateSessionResponse { } -// === Сообщения для OAuth2 SSO === - -message GenerateOauthCodeRequest { - string user_id = 1; - string client_id = 2; - string redirect_uri = 3; -} - -message GenerateOauthCodeResponse { - string code = 1; -} - -message ExchangeOauthCodeRequest { - string code = 1; - string client_id = 2; - string client_secret = 3; -} - -message ExchangeOauthCodeResponse { - string access_token = 1; - int32 expires_in = 2; -} - message SystemCreateAccountRequest { string username = 1; string password_hash = 2; // Хеш пароля генерирует Admin Service и передает сюда diff --git a/proto/sso/oauth.proto b/proto/sso/oauth.proto new file mode 100644 index 0000000..afea48b --- /dev/null +++ b/proto/sso/oauth.proto @@ -0,0 +1,104 @@ +syntax = "proto3"; + +package oauth.v1; + +option go_package = "git.lendry.ru/lendry-erp/proto.git/go;pb"; + +service OauthService { + // === Базовый SSO (вызывается из Gateway / Графаны) === + rpc GenerateOauthCode (GenerateOauthCodeRequest) returns (GenerateOauthCodeResponse); + rpc ExchangeOauthCode (ExchangeOauthCodeRequest) returns (ExchangeOauthCodeResponse); + + // === Системные методы для Админки (Управление клиентами) === + rpc SystemCreateOauthClient (SystemCreateOauthClientRequest) returns (SystemCreateOauthClientResponse); + rpc SystemGetOauthClients (SystemGetOauthClientsRequest) returns (SystemGetOauthClientsResponse); + rpc SystemUpdateOauthClient (SystemUpdateOauthClientRequest) returns (SystemUpdateOauthClientResponse); + rpc SystemResetOauthSecret (SystemResetOauthSecretRequest) returns (SystemResetOauthSecretResponse); + rpc SystemDeleteOauthClient (SystemDeleteOauthClientRequest) returns (SystemDeleteOauthClientResponse); +} + +// --- Сообщения для базового SSO --- + +message GenerateOauthCodeRequest { + string user_id = 1; + string client_id = 2; + string redirect_uri = 3; +} + +message GenerateOauthCodeResponse { + string code = 1; +} + +message ExchangeOauthCodeRequest { + string code = 1; + string client_id = 2; + string client_secret = 3; +} + +message ExchangeOauthCodeResponse { + string access_token = 1; + int32 expires_in = 2; +} + +// --- Сообщения для управления клиентами (Yandex/Google style) --- + +message SystemCreateOauthClientRequest { + string name = 1; // Название приложения (например, "Grafana Analytics") + repeated string redirect_uris = 2; // Список разрешенных коллбеков + optional string description = 3; // Описание (для админки) +} + +message SystemCreateOauthClientResponse { + string id = 1; // Внутренний ID в базе + string name = 2; + string client_id = 3; // Публичный ID клиента (app_...) + string plain_secret = 4; // ВАЖНО: Чистый секрет. Отдается ТОЛЬКО здесь один раз! + repeated string redirect_uris = 5; +} + +message OauthClientItem { + string id = 1; + string name = 2; + string client_id = 3; + repeated string redirect_uris = 4; + optional string description = 5; + int64 created_at = 6; + // Обратите внимание: поля secret здесь нет! Секрет нельзя получить списком. +} + +message SystemGetOauthClientsRequest { + int32 limit = 1; + int32 offset = 2; +} + +message SystemGetOauthClientsResponse { + repeated OauthClientItem clients = 1; + int32 total = 2; +} + +message SystemUpdateOauthClientRequest { + string client_id = 1; + optional string name = 2; + repeated string redirect_uris = 3; // Если передано, полностью перезаписывает старые + optional string description = 4; +} + +message SystemUpdateOauthClientResponse { + bool success = 1; +} + +message SystemResetOauthSecretRequest { + string client_id = 1; +} + +message SystemResetOauthSecretResponse { + string new_plain_secret = 1; // Возвращаем новый сгенерированный секрет +} + +message SystemDeleteOauthClientRequest { + string client_id = 1; +} + +message SystemDeleteOauthClientResponse { + bool success = 1; +} \ No newline at end of file diff --git a/src/proto/paths.ts b/src/proto/paths.ts index 7b27fc6..656cc0d 100644 --- a/src/proto/paths.ts +++ b/src/proto/paths.ts @@ -5,6 +5,7 @@ export const PROTO_PATHS = { LDAP_AUTH: join(__dirname, "../../proto/sso/ldap-auth.proto"), ACCOUNT: join(__dirname, "../../proto/sso/account.proto"), TWOFA: join(__dirname, "../../proto/sso/twofa.proto"), + OAUTH: join(__dirname, "../../proto/sso/oauth.proto"), ADMIN: join(__dirname, "../../proto/admin/admin-account.proto"), RBAC: join(__dirname, "../../proto/admin/rbac.proto"), USERS: join(__dirname, "../../proto/users/users.proto"),