@sasjs/adapter 3.10.10 → 3.10.11
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/index.js +2 -2
- package/node/index.js +2 -2
- package/node/types/errors/InvalidSASjsCsrfError.d.ts +3 -0
- package/package.json +1 -1
- package/src/auth/AuthManager.ts +10 -2
- package/src/request/RequestClient.ts +12 -4
- package/src/types/errors/InvalidSASjsCsrfError.ts +9 -0
- package/types/errors/InvalidSASjsCsrfError.d.ts +3 -0
- package/node/types/errors/InvalidCsrfError.d.ts +0 -3
- package/src/types/errors/InvalidCsrfError.ts +0 -9
- package/types/errors/InvalidCsrfError.d.ts +0 -3
package/package.json
CHANGED
package/src/auth/AuthManager.ts
CHANGED
|
@@ -223,9 +223,17 @@ export class AuthManager {
|
|
|
223
223
|
|
|
224
224
|
private async getNewLoginForm() {
|
|
225
225
|
if (this.serverType === ServerType.Sasjs) {
|
|
226
|
-
// server will be sending CSRF
|
|
226
|
+
// server will be sending CSRF token in response,
|
|
227
|
+
// need to save in cookie so that,
|
|
227
228
|
// http client will use it automatically
|
|
228
|
-
return this.requestClient.get('/', undefined)
|
|
229
|
+
return this.requestClient.get('/', undefined).then(({ result }) => {
|
|
230
|
+
const cookie =
|
|
231
|
+
/<script>document.cookie = '(XSRF-TOKEN=.*; Max-Age=86400; SameSite=Strict; Path=\/;)'<\/script>/.exec(
|
|
232
|
+
result as string
|
|
233
|
+
)?.[1]
|
|
234
|
+
|
|
235
|
+
if (cookie) document.cookie = cookie
|
|
236
|
+
})
|
|
229
237
|
}
|
|
230
238
|
|
|
231
239
|
const { result: formResponse } = await this.requestClient.get<string>(
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
parseSourceCode,
|
|
20
20
|
createAxiosInstance
|
|
21
21
|
} from '../utils'
|
|
22
|
-
import {
|
|
22
|
+
import { InvalidSASjsCsrfError } from '../types/errors/InvalidSASjsCsrfError'
|
|
23
23
|
|
|
24
24
|
export interface HttpClient {
|
|
25
25
|
get<T>(
|
|
@@ -499,12 +499,20 @@ export class RequestClient implements HttpClient {
|
|
|
499
499
|
throw e
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
if (e instanceof
|
|
503
|
-
// Fetching root
|
|
502
|
+
if (e instanceof InvalidSASjsCsrfError) {
|
|
503
|
+
// Fetching root and creating CSRF cookie
|
|
504
504
|
await this.httpClient
|
|
505
505
|
.get('/', {
|
|
506
506
|
withCredentials: true
|
|
507
507
|
})
|
|
508
|
+
.then((response) => {
|
|
509
|
+
const cookie =
|
|
510
|
+
/<script>document.cookie = '(XSRF-TOKEN=.*; Max-Age=86400; SameSite=Strict; Path=\/;)'<\/script>/.exec(
|
|
511
|
+
response.data
|
|
512
|
+
)?.[1]
|
|
513
|
+
|
|
514
|
+
if (cookie) document.cookie = cookie
|
|
515
|
+
})
|
|
508
516
|
.catch((err) => {
|
|
509
517
|
throw prefixMessage(err, 'Error while re-fetching CSRF token.')
|
|
510
518
|
})
|
|
@@ -615,7 +623,7 @@ export const throwIfError = (response: AxiosResponse) => {
|
|
|
615
623
|
typeof response.data === 'string' &&
|
|
616
624
|
response.data.toLowerCase() === 'invalid csrf token!'
|
|
617
625
|
) {
|
|
618
|
-
throw new
|
|
626
|
+
throw new InvalidSASjsCsrfError()
|
|
619
627
|
}
|
|
620
628
|
break
|
|
621
629
|
case 401:
|