auth-strategy-manager 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,301 @@
1
+ # Auth Strategy Manager
2
+
3
+ [![npm version](https://badge.fury.io/js/auth-strategy-manager.svg)](https://badge.fury.io/js/auth-strategy-manager)
4
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
5
+
6
+ A flexible library for managing authentication with support for multiple strategies. Allows easy integration of various authentication methods (Keycloak, REST API, custom) into a unified interface.
7
+
8
+ ## 🌍 Documentation in Other Languages
9
+
10
+ - [πŸ‡·πŸ‡Ί Русский (Russian)](README_RU.md)
11
+ - [πŸ‡ΊπŸ‡Έ English (Current)](README.md)
12
+
13
+ ## πŸ“¦ Packages
14
+
15
+ This repository contains the following packages:
16
+
17
+ - **[@auth-strategy-manager/core](https://www.npmjs.com/package/@auth-strategy-manager/core)** - Core authentication strategy manager: provides the main classes and interfaces for managing authentication strategies, including `AuthStrategyManager`, `Strategy`, `StrategyHelper`, error classes, and constants.
18
+ - **[@auth-strategy-manager/keycloak](https://www.npmjs.com/package/@auth-strategy-manager/keycloak)** - Keycloak strategy
19
+ - **[@auth-strategy-manager/rest](https://www.npmjs.com/package/@auth-strategy-manager/rest)** - REST API strategy
20
+
21
+ ## πŸš€ Quick Start
22
+
23
+ ### Install Core Package
24
+
25
+ ```bash
26
+ npm install @auth-strategy-manager/core
27
+ ```
28
+
29
+ ### Install with Keycloak Strategy
30
+
31
+ ```bash
32
+ npm install @auth-strategy-manager/core @auth-strategy-manager/keycloak keycloak-js
33
+ ```
34
+
35
+ ### Install with REST Strategy
36
+
37
+ ```bash
38
+ npm install @auth-strategy-manager/core @auth-strategy-manager/rest axios
39
+ ```
40
+
41
+ ### Install All Packages
42
+
43
+ ```bash
44
+ npm install @auth-strategy-manager/core @auth-strategy-manager/keycloak @auth-strategy-manager/rest keycloak-js axios
45
+ ```
46
+
47
+ ## πŸ”§ Usage
48
+
49
+ ### Basic Usage with Core Only
50
+
51
+ ```typescript
52
+ import { AuthStrategyManager, Strategy } from '@auth-strategy-manager/core';
53
+
54
+ // Create custom strategy
55
+ class CustomStrategy implements Strategy {
56
+ readonly name = 'custom';
57
+
58
+ public checkAuth = async (): Promise<boolean> => {
59
+ // Your authentication sign-ic
60
+ return true;
61
+ };
62
+
63
+ public signIn = async <T = unknown, D = undefined>(config?: D): Promise<T> => {
64
+ // Your sign in sign-ic
65
+ return {} as T;
66
+ };
67
+
68
+ public signUp = async <T = unknown, D = undefined>(config?: D): Promise<T> => {
69
+ // Your sign up sign-ic
70
+ return {} as T;
71
+ };
72
+
73
+ public signOut = async (): Promise<void> => {
74
+ // Your sign out sign-ic
75
+ this.clearStorage();
76
+ };
77
+
78
+ public refreshToken = async <T>(args?: T): Promise<void> => {
79
+ // Your token refresh sign-ic
80
+ };
81
+
82
+ public clear = (): void => {
83
+ // Your clear logic
84
+ };
85
+ }
86
+
87
+ // Use with strategy manager
88
+ const authManager = new AuthStrategyManager([new CustomStrategy()]);
89
+ ```
90
+
91
+ ### AuthStrategyManager API
92
+
93
+ Main class for managing authentication strategies.
94
+
95
+ #### Constructor
96
+
97
+ ```typescript
98
+ constructor(strategies: Strategy[])
99
+ ```
100
+
101
+ Creates a new AuthStrategyManager instance with the provided strategies.
102
+
103
+ #### Properties
104
+
105
+ - `strategiesCount: number` - Total number of registered strategies
106
+ - `strategy: Strategy` - Currently active strategy
107
+ - `startUrl: string | undefined` - URL to redirect after authentication
108
+
109
+ #### Methods
110
+
111
+ - `checkAuth(): Promise<boolean>` - Check authentication status across all strategies. Returns true if any strategy is authenticated.
112
+ - `setStrategies(strategies: Strategy[]): Promise<void>` - Replace all strategies with new ones
113
+ - `use(strategyName: string): void` - Set the active strategy by name
114
+ - `clear(): void` - Clear authentication state and reset all strategies
115
+
116
+ #### Usage Examples
117
+
118
+ ```typescript
119
+ // Create manager with strategies
120
+ const authManager = new AuthStrategyManager([strategy1, strategy2]);
121
+
122
+ // Check if user is authenticated
123
+ const isAuthenticated = await authManager.checkAuth();
124
+
125
+ // Switch to specific strategy
126
+ authManager.use('keycloak');
127
+
128
+ // Get current active strategy
129
+ const currentStrategy = authManager.strategy;
130
+
131
+ // Clear all authentication data
132
+ authManager.clear();
133
+ ```
134
+
135
+ ### Using Keycloak Strategy
136
+
137
+ ```typescript
138
+ import { AuthStrategyManager } from '@auth-strategy-manager/core';
139
+ import { KeycloakStrategy } from '@auth-strategy-manager/keycloak';
140
+
141
+ const keycloakStrategy = new KeycloakStrategy({
142
+ keycloak: {
143
+ realm: 'my-realm',
144
+ url: 'https://keycloak.example.com',
145
+ clientId: 'my-client'
146
+ }
147
+ });
148
+
149
+ const authManager = new AuthStrategyManager([keycloakStrategy]);
150
+ ```
151
+
152
+ ### Using REST Strategy
153
+
154
+ ```typescript
155
+ import { AuthStrategyManager } from '@auth-strategy-manager/core';
156
+ import { RestStrategy } from '@auth-strategy-manager/rest';
157
+
158
+ const restStrategy = new RestStrategy({
159
+ checkAuth: { url: '/api/auth/check-auth', method: 'GET' },
160
+ signIn: { url: '/api/auth/sign-in', method: 'POST' },
161
+ signUp: { url: '/api/auth/sign-up', method: 'POST' },
162
+ signOut: { url: '/api/auth/sign-out', method: 'POST' },
163
+ refresh: { url: '/api/auth/refresh', method: 'POST' }
164
+ });
165
+
166
+ const authManager = new AuthStrategyManager([restStrategy]);
167
+
168
+ // Check authentication
169
+ const isAuthenticated = await restStrategy.checkAuth();
170
+
171
+ // Sign out
172
+ await restStrategy.signOut();
173
+
174
+ // Clear state
175
+ restStrategy.clear();
176
+ ```
177
+
178
+ ### Using Multiple Strategies
179
+
180
+ ```typescript
181
+ import { AuthStrategyManager } from '@auth-strategy-manager/core';
182
+ import { KeycloakStrategy } from '@auth-strategy-manager/keycloak';
183
+ import { RestStrategy } from '@auth-strategy-manager/rest';
184
+
185
+ const keycloakStrategy = new KeycloakStrategy({
186
+ keycloak: {
187
+ realm: 'my-realm',
188
+ url: 'https://keycloak.example.com',
189
+ clientId: 'my-client'
190
+ }
191
+ });
192
+
193
+ const restStrategy = new RestStrategy({
194
+ check: { url: '/api/auth/check-auth', method: 'GET' },
195
+ signIn: { url: '/api/auth/sign-in', method: 'POST' },
196
+ signUp: { url: '/api/auth/sign-up', method: 'POST' },
197
+ signOut: { url: '/api/auth/sign-out', method: 'POST' },
198
+ refresh: { url: '/api/auth/refresh', method: 'POST' }
199
+ });
200
+
201
+ const authManager = new AuthStrategyManager([keycloakStrategy, restStrategy]);
202
+
203
+ // Check authentication (will try both strategies)
204
+ const isAuthenticated = await authManager.check();
205
+ ```
206
+
207
+ ## πŸ—οΈ Architecture
208
+
209
+ ### Core Package (@auth-strategy-manager/core)
210
+
211
+ Contains the main classes and interfaces:
212
+
213
+ - `AuthStrategyManager` - Main manager class
214
+ - `Strategy` - Interface for all strategies
215
+ - `StrategyHelper` - Helper class for state management
216
+ - Error classes and constants
217
+
218
+ ### Keycloak Package (@auth-strategy-manager/keycloak)
219
+
220
+ Provides Keycloak integration:
221
+
222
+ - `KeycloakStrategy` - Keycloak authentication strategy
223
+ - Keycloak-specific configuration types
224
+
225
+ ### REST Package (@auth-strategy-manager/rest)
226
+
227
+ Provides REST API integration:
228
+
229
+ - `RestStrategy` - REST API authentication strategy
230
+ - REST-specific configuration types
231
+
232
+ ## πŸ“– Documentation
233
+
234
+ - [Core Package Documentation](https://www.npmjs.com/package/@auth-strategy-manager/core)
235
+ - [Keycloak Strategy Documentation](https://www.npmjs.com/package/@auth-strategy-manager/keycloak)
236
+ - [REST Strategy Documentation](https://www.npmjs.com/package/@auth-strategy-manager/rest)
237
+
238
+ ## πŸ§ͺ Development
239
+
240
+ ### Setup
241
+
242
+ ```bash
243
+ # Install dependencies
244
+ npm install
245
+
246
+ # Build all packages
247
+ npm run build
248
+
249
+ # Build specific package
250
+ npm run build --workspace=@auth-strategy-manager/core
251
+ ```
252
+
253
+ ### Publishing
254
+
255
+ ```bash
256
+ # Publish all packages
257
+ npm run publish:all
258
+
259
+ # Publish specific package
260
+ npm run publish:core
261
+ npm run publish:keycloak
262
+ npm run publish:rest
263
+ ```
264
+
265
+ ## πŸ“ License
266
+
267
+ ISC License
268
+
269
+ ## 🀝 Contributing
270
+
271
+ 1. Fork the repository
272
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
273
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
274
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
275
+ 5. Open a Pull Request
276
+
277
+ ## πŸ“ž Support
278
+
279
+ If you have questions or issues, create an issue in the GitHub repository.
280
+
281
+ ---
282
+
283
+ **Auth Strategy Manager** - make authentication simple and flexible! πŸ”
284
+
285
+ ### Strategy Interface
286
+
287
+ ```typescript
288
+ interface Strategy {
289
+ name: string;
290
+ token?: string;
291
+ isAuthenticated?: boolean;
292
+ startUrl?: string;
293
+ signInUrl?: string;
294
+
295
+ checkAuth(): Promise<boolean>;
296
+ signIn<T = unknown, D = undefined>(config?: D): Promise<T>;
297
+ signUp<T = unknown, D = undefined>(config?: D): Promise<T>;
298
+ signOut(): Promise<void>;
299
+ refreshToken<T>(args?: T): Promise<void>;
300
+ }
301
+ ```
package/README_RU.md ADDED
@@ -0,0 +1,299 @@
1
+ # Auth Strategy Manager
2
+
3
+ [![npm version](https://badge.fury.io/js/auth-strategy-manager.svg)](https://badge.fury.io/js/auth-strategy-manager)
4
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
5
+
6
+ Гибкая Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ° для управлСния Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠ΅ΠΉ с ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΎΠΉ мноТСствСнных стратСгий. ΠŸΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ‚ Π»Π΅Π³ΠΊΠΎ ΠΈΠ½Ρ‚Π΅Π³Ρ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Ρ€Π°Π·Π»ΠΈΡ‡Π½Ρ‹Π΅ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ (Keycloak, REST API, кастомныС) Π² Π΅Π΄ΠΈΠ½Ρ‹ΠΉ интСрфСйс.
7
+
8
+ ## 🌍 ДокумСнтация Π½Π° Π΄Ρ€ΡƒΠ³ΠΈΡ… языках
9
+
10
+ - [πŸ‡ΊπŸ‡Έ English (Английский)](README.md)
11
+ - [πŸ‡·πŸ‡Ί Русский (Π’Π΅ΠΊΡƒΡ‰ΠΈΠΉ)](README_RU.md)
12
+
13
+ ## πŸ“¦ ΠŸΠ°ΠΊΠ΅Ρ‚Ρ‹
14
+
15
+ Π­Ρ‚ΠΎΡ‚ Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ содСрТит ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ ΠΏΠ°ΠΊΠ΅Ρ‚Ρ‹:
16
+
17
+ - **[@auth-strategy-manager/core](https://www.npmjs.com/package/@auth-strategy-manager/core)** β€” основной ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ€ стратСгий Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ: содСрТит Π³Π»Π°Π²Π½Ρ‹Π΅ классы ΠΈ интСрфСйсы для управлСния стратСгиями Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ `AuthStrategyManager`, `Strategy`, `StrategyHelper`, классы ошибок ΠΈ константы.
18
+ - **[@auth-strategy-manager/keycloak](https://www.npmjs.com/package/@auth-strategy-manager/keycloak)** β€” стратСгия Keycloak
19
+ - **[@auth-strategy-manager/rest](https://www.npmjs.com/package/@auth-strategy-manager/rest)** β€” стратСгия REST API
20
+
21
+ ## πŸš€ Быстрый старт
22
+
23
+ ### Установка основного ΠΏΠ°ΠΊΠ΅Ρ‚Π°
24
+
25
+ ```bash
26
+ npm install @auth-strategy-manager/core
27
+ ```
28
+
29
+ ### Установка с Keycloak стратСгиСй
30
+
31
+ ```bash
32
+ npm install @auth-strategy-manager/core @auth-strategy-manager/keycloak keycloak-js
33
+ ```
34
+
35
+ ### Установка с REST стратСгиСй
36
+
37
+ ```bash
38
+ npm install @auth-strategy-manager/core @auth-strategy-manager/rest axios
39
+ ```
40
+
41
+ ### Установка всСх ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ²
42
+
43
+ ```bash
44
+ npm install @auth-strategy-manager/core @auth-strategy-manager/keycloak @auth-strategy-manager/rest keycloak-js axios
45
+ ```
46
+
47
+ ## πŸ”§ ИспользованиС
48
+
49
+ ### Π‘Π°Π·ΠΎΠ²ΠΎΠ΅ использованиС Ρ‚ΠΎΠ»ΡŒΠΊΠΎ с core
50
+
51
+ ```typescript
52
+ import { AuthStrategyManager, Strategy } from '@auth-strategy-manager/core';
53
+
54
+ // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ кастомной стратСгии
55
+ class CustomStrategy implements Strategy {
56
+ readonly name = 'custom';
57
+
58
+ public checkAuth = async (): Promise<boolean> => {
59
+ // Π’Π°ΡˆΠ° Π»ΠΎΠ³ΠΈΠΊΠ° Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ
60
+ return true;
61
+ };
62
+
63
+ public signIn = async <T = unknown, D = undefined>(config?: D): Promise<T> => {
64
+ // Π’Π°ΡˆΠ° Π»ΠΎΠ³ΠΈΠΊΠ° Π²Ρ…ΠΎΠ΄Π°
65
+ return {} as T;
66
+ };
67
+
68
+ public signUp = async <T = unknown, D = undefined>(config?: D): Promise<T> => {
69
+ // Π’Π°ΡˆΠ° Π»ΠΎΠ³ΠΈΠΊΠ° рСгистрации
70
+ return {} as T;
71
+ };
72
+
73
+ public signOut = async (): Promise<void> => {
74
+ // Π’Π°ΡˆΠ° Π»ΠΎΠ³ΠΈΠΊΠ° Π²Ρ‹Ρ…ΠΎΠ΄Π°
75
+ this.clearStorage();
76
+ };
77
+
78
+ public refreshToken = async <T>(args?: T): Promise<void> => {
79
+ // Π’Π°ΡˆΠ° Π»ΠΎΠ³ΠΈΠΊΠ° обновлСния Ρ‚ΠΎΠΊΠ΅Π½Π°
80
+ };
81
+
82
+ public clear = (): void => {
83
+ // Π’Π°ΡˆΠ° Π»ΠΎΠ³ΠΈΠΊΠ° очистки
84
+ };
85
+ }
86
+
87
+ // ИспользованиС с ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ€ΠΎΠΌ стратСгий
88
+ const authManager = new AuthStrategyManager([new CustomStrategy()]);
89
+ ```
90
+
91
+ ### AuthStrategyManager API
92
+
93
+ Π“Π»Π°Π²Π½Ρ‹ΠΉ класс для управлСния стратСгиями Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ.
94
+
95
+ #### ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€
96
+
97
+ ```typescript
98
+ constructor(strategies: Strategy[])
99
+ ```
100
+
101
+ Π‘ΠΎΠ·Π΄Π°Π΅Ρ‚ Π½ΠΎΠ²Ρ‹ΠΉ экзСмпляр AuthStrategyManager с прСдоставлСнными стратСгиями.
102
+
103
+ #### Бвойства
104
+
105
+ - `strategiesCount: number` - ΠžΠ±Ρ‰Π΅Π΅ количСство зарСгистрированных стратСгий
106
+ - `strategy: Strategy` - ВСкущая активная стратСгия
107
+ - `startUrl: string | undefined` - URL для пСрСнаправлСния послС Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ
108
+
109
+ #### ΠœΠ΅Ρ‚ΠΎΠ΄Ρ‹
110
+
111
+ - `checkAuth(): Promise<boolean>` - ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡΠ΅Ρ‚ статус Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ ΠΏΠΎ всСм стратСгиям. Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ true, Ссли любая стратСгия Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΡ†ΠΈΡ€ΠΎΠ²Π°Π½Π°.
112
+ - `setStrategies(strategies: Strategy[]): Promise<void>` - ЗамСняСт всС стратСгии Π½ΠΎΠ²Ρ‹ΠΌΠΈ
113
+ - `use(strategyName: string): void` - УстанавливаСт Π°ΠΊΡ‚ΠΈΠ²Π½ΡƒΡŽ ΡΡ‚Ρ€Π°Ρ‚Π΅Π³ΠΈΡŽ ΠΏΠΎ ΠΈΠΌΠ΅Π½ΠΈ
114
+ - `clear(): void` - ΠžΡ‡ΠΈΡ‰Π°Π΅Ρ‚ состояниС Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ ΠΈ сбрасываСт всС стратСгии
115
+
116
+ #### ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования
117
+
118
+ ```typescript
119
+ // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ€Π° со стратСгиями
120
+ const authManager = new AuthStrategyManager([strategy1, strategy2]);
121
+
122
+ // ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ
123
+ const isAuthenticated = await authManager.checkAuth();
124
+
125
+ // ΠŸΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π½Π° ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΡƒΡŽ ΡΡ‚Ρ€Π°Ρ‚Π΅Π³ΠΈΡŽ
126
+ authManager.use('keycloak');
127
+
128
+ // ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΉ стратСгии
129
+ const currentStrategy = authManager.strategy;
130
+
131
+ // ΠžΡ‡ΠΈΡΡ‚ΠΊΠ° всСх Π΄Π°Π½Π½Ρ‹Ρ… Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ
132
+ authManager.clear();
133
+ ```
134
+
135
+ ### Strategy Interface
136
+
137
+ ```typescript
138
+ interface Strategy {
139
+ name: string;
140
+ token?: string;
141
+ isAuthenticated?: boolean;
142
+ startUrl?: string;
143
+ signInUrl?: string;
144
+
145
+ checkAuth(): Promise<boolean>;
146
+ signIn<T = unknown, D = undefined>(config?: D): Promise<T>;
147
+ signUp<T = unknown, D = undefined>(config?: D): Promise<T>;
148
+ signOut(): Promise<void>;
149
+ refreshToken<T>(args?: T): Promise<void>;
150
+ }
151
+ ```
152
+
153
+ ### ИспользованиС Keycloak стратСгии
154
+
155
+ ```typescript
156
+ import { AuthStrategyManager } from '@auth-strategy-manager/core';
157
+ import { KeycloakStrategy } from '@auth-strategy-manager/keycloak';
158
+
159
+ const keycloakStrategy = new KeycloakStrategy({
160
+ keycloak: {
161
+ realm: 'my-realm',
162
+ url: 'https://keycloak.example.com',
163
+ clientId: 'my-client'
164
+ }
165
+ });
166
+
167
+ const authManager = new AuthStrategyManager([keycloakStrategy]);
168
+ ```
169
+
170
+ ### ИспользованиС REST стратСгии
171
+
172
+ ```typescript
173
+ import { AuthStrategyManager } from '@auth-strategy-manager/core';
174
+ import { RestStrategy } from '@auth-strategy-manager/rest';
175
+
176
+ const restStrategy = new RestStrategy({
177
+ checkAuth: { url: '/api/auth/checkAuth', method: 'GET' },
178
+ signIn: { url: '/api/auth/sign-in', method: 'POST' },
179
+ signOut: { url: '/api/auth/sign-out', method: 'POST' },
180
+ refresh: { url: '/api/auth/refresh', method: 'POST' }
181
+ });
182
+
183
+ const authManager = new AuthStrategyManager([restStrategy]);
184
+
185
+ // ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ
186
+ const isAuthenticated = await restStrategy.checkAuth();
187
+
188
+ // Π’Ρ‹Ρ…ΠΎΠ΄ ΠΈΠ· систСмы
189
+ await restStrategy.signOut();
190
+
191
+ // ΠžΡ‡ΠΈΡΡ‚ΠΊΠ° состояния
192
+ restStrategy.clear();
193
+ ```
194
+
195
+ ### ИспользованиС мноТСствСнных стратСгий
196
+
197
+ ```typescript
198
+ import { AuthStrategyManager } from '@auth-strategy-manager/core';
199
+ import { KeycloakStrategy } from '@auth-strategy-manager/keycloak';
200
+ import { RestStrategy } from '@auth-strategy-manager/rest';
201
+
202
+ const keycloakStrategy = new KeycloakStrategy({
203
+ keycloak: {
204
+ realm: 'my-realm',
205
+ url: 'https://keycloak.example.com',
206
+ clientId: 'my-client'
207
+ }
208
+ });
209
+
210
+ const restStrategy = new RestStrategy({
211
+ checkAuth: { url: '/api/auth/check-auth', method: 'GET' },
212
+ signIn: { url: '/api/auth/sign-in', method: 'POST' },
213
+ signOut: { url: '/api/auth/sign-out', method: 'POST' },
214
+ refresh: { url: '/api/auth/refresh', method: 'POST' }
215
+ });
216
+
217
+ const authManager = new AuthStrategyManager([keycloakStrategy, restStrategy]);
218
+
219
+ // ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ (ΠΏΠΎΠΏΡ€ΠΎΠ±ΡƒΠ΅Ρ‚ ΠΎΠ±Π΅ стратСгии)
220
+ const isAuthenticated = await authManager.checkAuth();
221
+ ```
222
+
223
+ ## πŸ—οΈ АрхитСктура
224
+
225
+ ### Основной ΠΏΠ°ΠΊΠ΅Ρ‚ (@auth-strategy-manager/core)
226
+
227
+ Π‘ΠΎΠ΄Π΅Ρ€ΠΆΠΈΡ‚ основныС классы ΠΈ интСрфСйсы:
228
+
229
+ - `AuthStrategyManager` β€” Π³Π»Π°Π²Π½Ρ‹ΠΉ класс ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ€Π°
230
+ - `Strategy` β€” интСрфСйс для всСх стратСгий
231
+ - `StrategyHelper` β€” Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ класс для управлСния состояниСм
232
+ - ΠšΠ»Π°ΡΡΡ‹ ошибок ΠΈ константы
233
+
234
+ ### ΠŸΠ°ΠΊΠ΅Ρ‚ Keycloak (@auth-strategy-manager/keycloak)
235
+
236
+ ΠŸΡ€Π΅Π΄ΠΎΡΡ‚Π°Π²Π»ΡΠ΅Ρ‚ ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΡŽ с Keycloak:
237
+
238
+ - `KeycloakStrategy` β€” стратСгия Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ Keycloak
239
+ - Π’ΠΈΠΏΡ‹ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ для Keycloak
240
+
241
+ ### ΠŸΠ°ΠΊΠ΅Ρ‚ REST (@auth-strategy-manager/rest)
242
+
243
+ ΠŸΡ€Π΅Π΄ΠΎΡΡ‚Π°Π²Π»ΡΠ΅Ρ‚ ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΡŽ с REST API:
244
+
245
+ - `RestStrategy` β€” стратСгия Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ REST API
246
+ - Π’ΠΈΠΏΡ‹ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ для REST
247
+
248
+ ## πŸ“– ДокумСнтация
249
+
250
+ - [ДокумСнтация основного ΠΏΠ°ΠΊΠ΅Ρ‚Π°](https://www.npmjs.com/package/@auth-strategy-manager/core)
251
+ - [ДокумСнтация Keycloak стратСгии](https://www.npmjs.com/package/@auth-strategy-manager/keycloak)
252
+ - [ДокумСнтация REST стратСгии](https://www.npmjs.com/package/@auth-strategy-manager/rest)
253
+
254
+ ## πŸ§ͺ Π Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ°
255
+
256
+ ### Настройка
257
+
258
+ ```bash
259
+ # Установка зависимостСй
260
+ npm install
261
+
262
+ # Π‘Π±ΠΎΡ€ΠΊΠ° всСх ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ²
263
+ npm run build
264
+
265
+ # Π‘Π±ΠΎΡ€ΠΊΠ° ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠ³ΠΎ ΠΏΠ°ΠΊΠ΅Ρ‚Π°
266
+ npm run build --workspace=@auth-strategy-manager/core
267
+ ```
268
+
269
+ ### ΠŸΡƒΠ±Π»ΠΈΠΊΠ°Ρ†ΠΈΡ
270
+
271
+ ```bash
272
+ # ΠŸΡƒΠ±Π»ΠΈΠΊΠ°Ρ†ΠΈΡ всСх ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ²
273
+ npm run publish:all
274
+
275
+ # ΠŸΡƒΠ±Π»ΠΈΠΊΠ°Ρ†ΠΈΡ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠ³ΠΎ ΠΏΠ°ΠΊΠ΅Ρ‚Π°
276
+ npm run publish:core
277
+ npm run publish:keycloak
278
+ npm run publish:rest
279
+ ```
280
+
281
+ ## πŸ“ ЛицСнзия
282
+
283
+ ISC License
284
+
285
+ ## 🀝 Π’ΠΊΠ»Π°Π΄ Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚
286
+
287
+ 1. Π€ΠΎΡ€ΠΊΠ½ΠΈΡ‚Π΅ Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ
288
+ 2. Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Π²Π΅Ρ‚ΠΊΡƒ для Π½ΠΎΠ²ΠΎΠΉ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ (`git checkAuthout -b feature/amazing-feature`)
289
+ 3. ЗафиксируйтС измСнСния (`git commit -m 'Add amazing feature'`)
290
+ 4. ΠžΡ‚ΠΏΡ€Π°Π²ΡŒΡ‚Π΅ Π² Π²Π΅Ρ‚ΠΊΡƒ (`git push origin feature/amazing-feature`)
291
+ 5. ΠžΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ Pull Request
292
+
293
+ ## πŸ“ž ΠŸΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ°
294
+
295
+ Если Ρƒ вас Π΅ΡΡ‚ΡŒ вопросы ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡ‹, создайтС issue Π² GitHub Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΈ.
296
+
297
+ ---
298
+
299
+ **Auth Strategy Manager** - сдСлайтС Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΡŽ простой ΠΈ Π³ΠΈΠ±ΠΊΠΎΠΉ! πŸ”
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@auth-strategy-manager/core';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('@auth-strategy-manager/core');
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "auth-strategy-manager",
3
+ "version": "1.0.7",
4
+ "description": "Meta package for auth-strategy-manager. Installs core by default.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "keywords": [
8
+ "authentication",
9
+ "authorization",
10
+ "strategy",
11
+ "auth",
12
+ "core"
13
+ ],
14
+ "author": "azarov-serge <s.a.azarov@gmail.com>",
15
+ "license": "ISC",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/azarov-serge/auth-strategy-manager.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/azarov-serge/auth-strategy-manager/issues"
22
+ },
23
+ "homepage": "https://github.com/azarov-serge/auth-strategy-manager#readme",
24
+ "dependencies": {
25
+ "@auth-strategy-manager/core": "^1.0.5"
26
+ },
27
+ "scripts": {
28
+ "prepublishOnly": "cp ../README.md ./README.md && cp ../README_RU.md ./README_RU.md"
29
+ }
30
+ }