@progalaxyelabs/ngx-stonescriptphp-client 0.0.10 → 1.0.4
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/HLD.md +31 -0
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/dist/ngx-stonescriptphp-client/README.md +186 -0
- package/{fesm2022 → dist/ngx-stonescriptphp-client/fesm2022}/progalaxyelabs-ngx-stonescriptphp-client.mjs +262 -46
- package/dist/ngx-stonescriptphp-client/fesm2022/progalaxyelabs-ngx-stonescriptphp-client.mjs.map +1 -0
- package/dist/ngx-stonescriptphp-client/index.d.ts +184 -0
- package/docs/AUTH_COMPATIBILITY.md +310 -0
- package/docs/CHANGELOG.md +261 -0
- package/package.json +75 -18
- package/esm2022/lib/api-connection.service.mjs +0 -169
- package/esm2022/lib/api-response.model.mjs +0 -26
- package/esm2022/lib/auth.service.mjs +0 -14
- package/esm2022/lib/db.service.mjs +0 -14
- package/esm2022/lib/my-environment.model.mjs +0 -19
- package/esm2022/lib/ngx-stonescriptphp-client/ngx-stonescriptphp-client.module.mjs +0 -27
- package/esm2022/lib/signin-status.service.mjs +0 -23
- package/esm2022/lib/token.service.mjs +0 -55
- package/esm2022/progalaxyelabs-ngx-stonescriptphp-client.mjs +0 -5
- package/esm2022/public-api.mjs +0 -12
- package/fesm2022/progalaxyelabs-ngx-stonescriptphp-client.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/api-connection.service.d.ts +0 -23
- package/lib/api-response.model.d.ts +0 -9
- package/lib/auth.service.d.ts +0 -6
- package/lib/db.service.d.ts +0 -6
- package/lib/my-environment.model.d.ts +0 -20
- package/lib/ngx-stonescriptphp-client/ngx-stonescriptphp-client.module.d.ts +0 -10
- package/lib/signin-status.service.d.ts +0 -10
- package/lib/token.service.d.ts +0 -14
- package/public-api.d.ts +0 -8
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { ModuleWithProviders } from '@angular/core';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
import * as i1 from '@angular/common';
|
|
5
|
+
|
|
6
|
+
declare class TokenService {
|
|
7
|
+
private accessToken;
|
|
8
|
+
private refreshToken;
|
|
9
|
+
private lsAccessTokenKey;
|
|
10
|
+
private lsRefreshTokenKey;
|
|
11
|
+
constructor();
|
|
12
|
+
setTokens(accessToken: string, refreshToken: string): void;
|
|
13
|
+
setAccessToken(accessToken: string): void;
|
|
14
|
+
setRefreshToken(refreshToken: string): void;
|
|
15
|
+
getAccessToken(): string;
|
|
16
|
+
getRefreshToken(): string;
|
|
17
|
+
clear(): void;
|
|
18
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TokenService, never>;
|
|
19
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<TokenService>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class SigninStatusService {
|
|
23
|
+
status: BehaviorSubject<boolean>;
|
|
24
|
+
constructor();
|
|
25
|
+
signedOut(): void;
|
|
26
|
+
signedIn(): void;
|
|
27
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SigninStatusService, never>;
|
|
28
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SigninStatusService>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare class ApiResponse<DataType> {
|
|
32
|
+
private status;
|
|
33
|
+
private data;
|
|
34
|
+
private message;
|
|
35
|
+
constructor(status: string, data?: any, message?: string);
|
|
36
|
+
onOk(callback: (data: DataType) => void): ApiResponse<DataType>;
|
|
37
|
+
onNotOk(callback: (message: string, data: DataType) => void): ApiResponse<DataType>;
|
|
38
|
+
onError(callback: () => void): ApiResponse<DataType>;
|
|
39
|
+
isSuccess(): boolean;
|
|
40
|
+
isError(): boolean;
|
|
41
|
+
getData(): DataType | null;
|
|
42
|
+
getError(): string;
|
|
43
|
+
getStatus(): string;
|
|
44
|
+
getMessage(): string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type AuthMode = 'cookie' | 'body' | 'none';
|
|
48
|
+
interface AuthConfig {
|
|
49
|
+
/**
|
|
50
|
+
* Authentication mode:
|
|
51
|
+
* - 'cookie': Use httpOnly cookies + CSRF tokens (recommended, matches StoneScriptPHP v2.1.x)
|
|
52
|
+
* - 'body': Send tokens in request body (legacy mode)
|
|
53
|
+
* - 'none': No automatic token refresh
|
|
54
|
+
*/
|
|
55
|
+
mode: AuthMode;
|
|
56
|
+
/**
|
|
57
|
+
* Token refresh endpoint path
|
|
58
|
+
* @default '/auth/refresh' for cookie mode, '/user/refresh_access' for body mode
|
|
59
|
+
*/
|
|
60
|
+
refreshEndpoint?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Enable CSRF token support (required for cookie mode)
|
|
63
|
+
* @default true for cookie mode, false for body mode
|
|
64
|
+
*/
|
|
65
|
+
useCsrf?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Cookie name for refresh token
|
|
68
|
+
* @default 'refresh_token'
|
|
69
|
+
*/
|
|
70
|
+
refreshTokenCookieName?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Cookie name for CSRF token
|
|
73
|
+
* @default 'csrf_token'
|
|
74
|
+
*/
|
|
75
|
+
csrfTokenCookieName?: string;
|
|
76
|
+
/**
|
|
77
|
+
* CSRF header name
|
|
78
|
+
* @default 'X-CSRF-Token'
|
|
79
|
+
*/
|
|
80
|
+
csrfHeaderName?: string;
|
|
81
|
+
}
|
|
82
|
+
declare class MyEnvironmentModel {
|
|
83
|
+
production: boolean;
|
|
84
|
+
firebase: {
|
|
85
|
+
projectId: string;
|
|
86
|
+
appId: string;
|
|
87
|
+
databaseURL: string;
|
|
88
|
+
storageBucket: string;
|
|
89
|
+
locationId: string;
|
|
90
|
+
apiKey: string;
|
|
91
|
+
authDomain: string;
|
|
92
|
+
messagingSenderId: string;
|
|
93
|
+
measurementId: string;
|
|
94
|
+
};
|
|
95
|
+
apiServer: {
|
|
96
|
+
host: string;
|
|
97
|
+
};
|
|
98
|
+
chatServer: {
|
|
99
|
+
host: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Authentication configuration
|
|
103
|
+
* @default { mode: 'cookie', refreshEndpoint: '/auth/refresh', useCsrf: true }
|
|
104
|
+
*/
|
|
105
|
+
auth?: AuthConfig;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* CSRF Token Service
|
|
110
|
+
*
|
|
111
|
+
* Manages CSRF tokens for cookie-based authentication.
|
|
112
|
+
* Reads CSRF token from cookies and provides it for request headers.
|
|
113
|
+
*/
|
|
114
|
+
declare class CsrfService {
|
|
115
|
+
/**
|
|
116
|
+
* Get CSRF token from cookie
|
|
117
|
+
*/
|
|
118
|
+
getCsrfToken(cookieName?: string): string | null;
|
|
119
|
+
/**
|
|
120
|
+
* Check if CSRF token exists
|
|
121
|
+
*/
|
|
122
|
+
hasCsrfToken(cookieName?: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Clear CSRF token (for logout)
|
|
125
|
+
* Note: Client-side deletion is limited for httpOnly cookies
|
|
126
|
+
*/
|
|
127
|
+
clearCsrfToken(cookieName?: string): void;
|
|
128
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CsrfService, never>;
|
|
129
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CsrfService>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare class ApiConnectionService {
|
|
133
|
+
private tokens;
|
|
134
|
+
private signinStatus;
|
|
135
|
+
private environment;
|
|
136
|
+
private csrf;
|
|
137
|
+
private host;
|
|
138
|
+
private accessToken;
|
|
139
|
+
private authConfig;
|
|
140
|
+
constructor(tokens: TokenService, signinStatus: SigninStatusService, environment: MyEnvironmentModel, csrf: CsrfService);
|
|
141
|
+
private request;
|
|
142
|
+
private handleError;
|
|
143
|
+
get<DataType>(endpoint: string, queryParamsObj?: any): Promise<ApiResponse<DataType>>;
|
|
144
|
+
post<DataType>(pathWithQueryParams: string, data: any): Promise<ApiResponse<DataType>>;
|
|
145
|
+
put<DataType>(pathWithQueryParams: string, data: any): Promise<ApiResponse<DataType>>;
|
|
146
|
+
patch<DataType>(pathWithQueryParams: string, data: any): Promise<ApiResponse<DataType>>;
|
|
147
|
+
delete<DataType>(endpoint: string, queryParamsObj?: any): Promise<ApiResponse<DataType>>;
|
|
148
|
+
private includeAccessToken;
|
|
149
|
+
private refreshAccessTokenAndRetry;
|
|
150
|
+
refreshAccessToken(): Promise<boolean>;
|
|
151
|
+
/**
|
|
152
|
+
* Refresh access token using cookie-based auth (StoneScriptPHP v2.1.x default)
|
|
153
|
+
*/
|
|
154
|
+
private refreshAccessTokenCookieMode;
|
|
155
|
+
/**
|
|
156
|
+
* Refresh access token using body-based auth (legacy mode)
|
|
157
|
+
*/
|
|
158
|
+
private refreshAccessTokenBodyMode;
|
|
159
|
+
buildQueryString(options?: any): string;
|
|
160
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ApiConnectionService, never>;
|
|
161
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ApiConnectionService>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare class AuthService {
|
|
165
|
+
constructor();
|
|
166
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, never>;
|
|
167
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
declare class DbService {
|
|
171
|
+
constructor();
|
|
172
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DbService, never>;
|
|
173
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DbService>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare class NgxStoneScriptPhpClientModule {
|
|
177
|
+
static forRoot(environment: MyEnvironmentModel): ModuleWithProviders<NgxStoneScriptPhpClientModule>;
|
|
178
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgxStoneScriptPhpClientModule, never>;
|
|
179
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<NgxStoneScriptPhpClientModule, never, [typeof i1.CommonModule], never>;
|
|
180
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<NgxStoneScriptPhpClientModule>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export { ApiConnectionService, ApiResponse, AuthService, CsrfService, DbService, MyEnvironmentModel, NgxStoneScriptPhpClientModule, SigninStatusService, TokenService };
|
|
184
|
+
export type { AuthConfig, AuthMode };
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# Authentication Compatibility Guide
|
|
2
|
+
|
|
3
|
+
## StoneScriptPHP Framework vs ngx-stonescriptphp-client
|
|
4
|
+
|
|
5
|
+
This document outlines the authentication flow compatibility between the Angular client library and StoneScriptPHP backend framework (v2.1.x).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ⚠️ CRITICAL INCOMPATIBILITY FOUND
|
|
10
|
+
|
|
11
|
+
### Token Refresh Endpoint Mismatch
|
|
12
|
+
|
|
13
|
+
**CLIENT IMPLEMENTATION** (`api-connection.service.ts:187`):
|
|
14
|
+
```typescript
|
|
15
|
+
const refreshTokenUrl = this.host + 'user/refresh_access'
|
|
16
|
+
await fetch(refreshTokenUrl, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
body: JSON.stringify({
|
|
19
|
+
access_token: this.accessToken,
|
|
20
|
+
refresh_token: refreshToken
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**SERVER IMPLEMENTATION** (StoneScriptPHP `RefreshRoute.php`):
|
|
26
|
+
```php
|
|
27
|
+
// Default route: POST /auth/refresh
|
|
28
|
+
// OR custom: AuthRoutes::register($router, ['prefix' => '/api/auth']);
|
|
29
|
+
|
|
30
|
+
// Expected request:
|
|
31
|
+
// - Refresh token comes from httpOnly cookie (NOT request body)
|
|
32
|
+
// - CSRF token required in X-CSRF-Token header
|
|
33
|
+
// - Does NOT accept tokens in request body for security
|
|
34
|
+
|
|
35
|
+
// Response:
|
|
36
|
+
{
|
|
37
|
+
"status": "ok",
|
|
38
|
+
"data": {
|
|
39
|
+
"access_token": "eyJ...",
|
|
40
|
+
"expires_in": 900,
|
|
41
|
+
"token_type": "Bearer"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Issues Identified
|
|
47
|
+
|
|
48
|
+
#### 1. **Endpoint Path Mismatch**
|
|
49
|
+
- **Client expects**: `/user/refresh_access`
|
|
50
|
+
- **Server provides**: `/auth/refresh` (default) or custom prefix
|
|
51
|
+
|
|
52
|
+
#### 2. **Token Transmission Mismatch**
|
|
53
|
+
- **Client sends**: Tokens in JSON request body
|
|
54
|
+
- **Server expects**:
|
|
55
|
+
- Refresh token in httpOnly cookie (named `refresh_token`)
|
|
56
|
+
- CSRF token in `X-CSRF-Token` header
|
|
57
|
+
- **Does NOT read tokens from request body**
|
|
58
|
+
|
|
59
|
+
#### 3. **Security Model Mismatch**
|
|
60
|
+
- **Client**: Stores tokens in localStorage/sessionStorage (via TokenService)
|
|
61
|
+
- **Server**: Uses httpOnly cookies + CSRF protection (XSS-safe)
|
|
62
|
+
|
|
63
|
+
#### 4. **Response Format Mismatch**
|
|
64
|
+
- **Client expects**: `response.data.access_token`
|
|
65
|
+
- **Server returns**: `ApiResponse` where data is the second parameter:
|
|
66
|
+
```php
|
|
67
|
+
return new ApiResponse('ok', [
|
|
68
|
+
'access_token' => $token,
|
|
69
|
+
'expires_in' => 900,
|
|
70
|
+
'token_type' => 'Bearer'
|
|
71
|
+
]);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Authentication Flow Analysis
|
|
77
|
+
|
|
78
|
+
### StoneScriptPHP Framework Auth System
|
|
79
|
+
|
|
80
|
+
The framework provides **two authentication modes**:
|
|
81
|
+
|
|
82
|
+
#### Mode 1: Built-in Cookie-Based Auth (Secure, Recommended)
|
|
83
|
+
Located in `/src/Auth/Routes/`:
|
|
84
|
+
- `POST /auth/refresh` - Refresh access token using httpOnly cookies
|
|
85
|
+
- `POST /auth/logout` - Logout and invalidate refresh token
|
|
86
|
+
|
|
87
|
+
**Security Features**:
|
|
88
|
+
- httpOnly cookies prevent XSS attacks
|
|
89
|
+
- CSRF token protection
|
|
90
|
+
- Refresh token rotation
|
|
91
|
+
- Optional token blacklisting via `TokenStorageInterface`
|
|
92
|
+
|
|
93
|
+
**Registration**:
|
|
94
|
+
```php
|
|
95
|
+
// In your index.php or bootstrap
|
|
96
|
+
use StoneScriptPHP\Auth\AuthRoutes;
|
|
97
|
+
|
|
98
|
+
AuthRoutes::register($router, [
|
|
99
|
+
'prefix' => '/auth', // or '/api/auth'
|
|
100
|
+
'token_storage' => $tokenStorage // optional
|
|
101
|
+
]);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Mode 2: Custom Implementation (Templates)
|
|
105
|
+
Located in `/src/Templates/Auth/`:
|
|
106
|
+
- `email-password/LoginRoute.php.template`
|
|
107
|
+
- `email-password/RegisterRoute.php.template`
|
|
108
|
+
- `email-password/PasswordResetRoute.php.template`
|
|
109
|
+
- `mobile-otp/SendOtpRoute.php.template`
|
|
110
|
+
- And more...
|
|
111
|
+
|
|
112
|
+
**Note**: Templates are **scaffolding code** that developers customize. They show:
|
|
113
|
+
- Example status values: `'success'` vs `'ok'` (inconsistent!)
|
|
114
|
+
- Example token format
|
|
115
|
+
- Database queries
|
|
116
|
+
- But are NOT the actual built-in implementation
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Current Client Implementation Analysis
|
|
121
|
+
|
|
122
|
+
### What Works ✅
|
|
123
|
+
|
|
124
|
+
1. **HTTP Methods**: All match (GET, POST, PUT, PATCH, DELETE)
|
|
125
|
+
2. **ApiResponse Structure**: Compatible
|
|
126
|
+
- Client expects: `{ status: string, message: string, data: any }`
|
|
127
|
+
- Server returns: Same structure
|
|
128
|
+
3. **Bearer Token Authentication**: Client correctly adds `Authorization: Bearer {token}`
|
|
129
|
+
4. **Automatic 401 Retry**: Client attempts token refresh on 401 errors
|
|
130
|
+
|
|
131
|
+
### What's Broken ❌
|
|
132
|
+
|
|
133
|
+
1. **Token Refresh Flow**: Completely incompatible
|
|
134
|
+
- Different endpoint paths
|
|
135
|
+
- Different token transmission method
|
|
136
|
+
- Different security model
|
|
137
|
+
|
|
138
|
+
2. **AuthService**: Empty placeholder (no implementation)
|
|
139
|
+
|
|
140
|
+
3. **Login/Register Endpoints**: Not standardized
|
|
141
|
+
- Templates show `/api/auth/login` but customizable
|
|
142
|
+
- Response format varies (some templates use `'success'` vs `'ok'`)
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Compatibility Matrix
|
|
147
|
+
|
|
148
|
+
| Feature | Client (v0.0.13) | Framework (v2.1.x) | Compatible? |
|
|
149
|
+
|---------|------------------|-------------------|-------------|
|
|
150
|
+
| **HTTP Methods** | GET, POST, PUT, PATCH, DELETE | All supported | ✅ Yes |
|
|
151
|
+
| **ApiResponse Format** | `{status, message, data}` | Same | ✅ Yes |
|
|
152
|
+
| **Bearer Auth** | `Authorization: Bearer {token}` | Same | ✅ Yes |
|
|
153
|
+
| **Token Refresh Endpoint** | `/user/refresh_access` | `/auth/refresh` | ❌ No |
|
|
154
|
+
| **Token Storage** | localStorage | httpOnly cookies | ❌ No |
|
|
155
|
+
| **CSRF Protection** | Not implemented | Required | ❌ No |
|
|
156
|
+
| **Login Endpoint** | Not defined | Custom (templates) | ⚠️ Varies |
|
|
157
|
+
| **Token Format** | JWT in response body | JWT in cookie + body | ⚠️ Partial |
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Recommended Solutions
|
|
162
|
+
|
|
163
|
+
### Option 1: Update Client to Match Framework (Recommended)
|
|
164
|
+
|
|
165
|
+
**Pros**:
|
|
166
|
+
- Better security (httpOnly cookies)
|
|
167
|
+
- CSRF protection
|
|
168
|
+
- Aligns with framework best practices
|
|
169
|
+
|
|
170
|
+
**Cons**:
|
|
171
|
+
- Breaking change for existing users
|
|
172
|
+
- Requires cookie handling
|
|
173
|
+
|
|
174
|
+
**Implementation**:
|
|
175
|
+
1. Update `refreshAccessToken()` to:
|
|
176
|
+
- Call `POST /auth/refresh` with credentials: 'include'
|
|
177
|
+
- Send CSRF token from cookie
|
|
178
|
+
- Don't send tokens in body
|
|
179
|
+
2. Add `CsrfService` to manage CSRF tokens
|
|
180
|
+
3. Update `TokenService` to work with cookies
|
|
181
|
+
4. Add cookie configuration to `MyEnvironmentModel`
|
|
182
|
+
|
|
183
|
+
### Option 2: Add Server-Side Compatibility Endpoint
|
|
184
|
+
|
|
185
|
+
**Pros**:
|
|
186
|
+
- No client breaking changes
|
|
187
|
+
- Backward compatible
|
|
188
|
+
|
|
189
|
+
**Cons**:
|
|
190
|
+
- Less secure (tokens in body)
|
|
191
|
+
- Developers must implement it
|
|
192
|
+
|
|
193
|
+
**Implementation**:
|
|
194
|
+
Create custom route in StoneScriptPHP project:
|
|
195
|
+
```php
|
|
196
|
+
// src/App/Routes/LegacyRefreshRoute.php
|
|
197
|
+
class LegacyRefreshRoute implements IRouteHandler {
|
|
198
|
+
public function process(): ApiResponse {
|
|
199
|
+
// Read tokens from request body
|
|
200
|
+
$accessToken = request()->input['access_token'] ?? null;
|
|
201
|
+
$refreshToken = request()->input['refresh_token'] ?? null;
|
|
202
|
+
|
|
203
|
+
// Verify and refresh...
|
|
204
|
+
// Return new access token
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Register in routes.php
|
|
209
|
+
'POST' => [
|
|
210
|
+
'/user/refresh_access' => LegacyRefreshRoute::class
|
|
211
|
+
]
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Option 3: Make Client Configurable
|
|
215
|
+
|
|
216
|
+
**Pros**:
|
|
217
|
+
- Supports both modes
|
|
218
|
+
- Migration path
|
|
219
|
+
|
|
220
|
+
**Cons**:
|
|
221
|
+
- More complex
|
|
222
|
+
- Maintenance burden
|
|
223
|
+
|
|
224
|
+
**Implementation**:
|
|
225
|
+
```typescript
|
|
226
|
+
export interface AuthConfig {
|
|
227
|
+
mode: 'cookie' | 'body';
|
|
228
|
+
refreshEndpoint: string;
|
|
229
|
+
useCsrf: boolean;
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Migration Path for Existing Apps
|
|
236
|
+
|
|
237
|
+
For apps currently using the client with custom backends:
|
|
238
|
+
|
|
239
|
+
### Step 1: Check Your Backend Auth Implementation
|
|
240
|
+
```bash
|
|
241
|
+
# Does your backend match the client's expectations?
|
|
242
|
+
curl -X POST http://localhost:8000/user/refresh_access \
|
|
243
|
+
-H "Content-Type: application/json" \
|
|
244
|
+
-d '{"access_token": "...", "refresh_token": "..."}'
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Step 2: Update to StoneScriptPHP v2.1.x Auth
|
|
248
|
+
```php
|
|
249
|
+
// Option A: Use built-in secure auth
|
|
250
|
+
AuthRoutes::register($router, ['prefix' => '/api/auth']);
|
|
251
|
+
|
|
252
|
+
// Option B: Create legacy compatibility route
|
|
253
|
+
// See Option 2 above
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Step 3: Update Client Configuration
|
|
257
|
+
```typescript
|
|
258
|
+
// Wait for v0.0.14+ with auth config support
|
|
259
|
+
// OR implement custom auth service extending ApiConnectionService
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Action Items for Next Release (v0.0.14)
|
|
265
|
+
|
|
266
|
+
### Must Fix (Breaking Changes Acceptable):
|
|
267
|
+
1. ✅ Add configurable auth endpoints
|
|
268
|
+
2. ✅ Implement cookie-based auth mode
|
|
269
|
+
3. ✅ Add CSRF token support
|
|
270
|
+
4. ✅ Update AuthService with actual implementation
|
|
271
|
+
5. ✅ Document both auth modes
|
|
272
|
+
|
|
273
|
+
### Should Have:
|
|
274
|
+
1. Add login/register/logout helper methods
|
|
275
|
+
2. Add auth state management (RxJS)
|
|
276
|
+
3. Add auth guards/interceptors examples
|
|
277
|
+
4. Create migration guide with code examples
|
|
278
|
+
|
|
279
|
+
### Nice to Have:
|
|
280
|
+
1. Social auth helpers (Google, etc.)
|
|
281
|
+
2. Password reset flow helpers
|
|
282
|
+
3. Email verification helpers
|
|
283
|
+
4. Multi-factor auth support
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Conclusion
|
|
288
|
+
|
|
289
|
+
**Current Status**: ❌ **NOT FULLY COMPATIBLE**
|
|
290
|
+
|
|
291
|
+
The v0.0.13 client library is **compatible for general API calls** (CRUD operations) but **incompatible for authentication flows**.
|
|
292
|
+
|
|
293
|
+
### For Developers:
|
|
294
|
+
- ✅ Use for: CRUD API calls with manually managed auth
|
|
295
|
+
- ❌ Don't use: Built-in token refresh (broken)
|
|
296
|
+
- ⚠️ Workaround: Implement custom refresh logic or wait for v0.0.14
|
|
297
|
+
|
|
298
|
+
### For Package Maintainers:
|
|
299
|
+
- 🔴 **Priority**: Fix auth compatibility before promoting package
|
|
300
|
+
- 📝 Add clear warnings in README about auth limitations
|
|
301
|
+
- 🚀 Plan v0.0.14 with breaking changes to align with framework
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## References
|
|
306
|
+
|
|
307
|
+
- **StoneScriptPHP Auth**: `/src/Auth/Routes/RefreshRoute.php`
|
|
308
|
+
- **Client Auth**: `/projects/ngx-stonescriptphp-client/src/lib/api-connection.service.ts`
|
|
309
|
+
- **Framework Version**: v2.1.x (on Packagist)
|
|
310
|
+
- **Client Version**: v0.0.13
|