fix: 🐛 Fix för login block 24mars
Denna gör så att bl.a. x-xsrf-token7 fungerar samt lägger till cachebusting parameter på childcontroller
This commit is contained in:
parent
52ba3726fe
commit
7667a5e25a
13
lib/api.ts
13
lib/api.ts
|
@ -131,7 +131,7 @@ export class Api extends EventEmitter {
|
|||
}
|
||||
|
||||
private async retrieveApiKey(): Promise<void> {
|
||||
const url = routes.startBundle
|
||||
const url = routes.childcontrollerScript
|
||||
const session = this.getRequestInit()
|
||||
const response = await this.fetch('startBundle', url, session)
|
||||
const text = await response.text()
|
||||
|
@ -163,9 +163,12 @@ export class Api extends EventEmitter {
|
|||
const response = await this.fetch('childcontrollerScript', url, {})
|
||||
const text = await response.text()
|
||||
|
||||
const xsrfRegExp = /'x-xsrf-token2':[ ]?'([\w\d_-]+)'/gim
|
||||
const xsrfRegExp = /'(x-xsrf-token[\d]+)':[ ]?'([\w\d_-]+)'/gim
|
||||
const xsrfMatches = xsrfRegExp.exec(text)
|
||||
return xsrfMatches && xsrfMatches.length > 1 ? xsrfMatches[1] : ''
|
||||
|
||||
return xsrfMatches && xsrfMatches.length > 2
|
||||
? {'xsrfTokenName': xsrfMatches[1], 'xsrfTokenValue':xsrfMatches[2]}
|
||||
: {'xsrfTokenName': 'x-xsrf-token', 'xsrfTokenValue':''}
|
||||
}
|
||||
|
||||
private async retrieveAuthToken(url: string, authBody: string): Promise<string> {
|
||||
|
@ -186,12 +189,12 @@ export class Api extends EventEmitter {
|
|||
this.cookieManager.clearAll()
|
||||
|
||||
// Perform request
|
||||
const createItemXsrfToken = await this.retrieveCreateItemXsrfToken(routes.childcontrollerScript)
|
||||
const {xsrfTokenName, xsrfTokenValue} = await this.retrieveCreateItemXsrfToken(routes.childcontrollerScript)
|
||||
const response = await this.fetch('createItem', url, {
|
||||
...session,
|
||||
headers: {
|
||||
...session.headers,
|
||||
'x-xsrf-token2': createItemXsrfToken
|
||||
[xsrfTokenName] : xsrfTokenValue
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -54,4 +54,4 @@ export const hemPage = 'https://etjanst.stockholm.se/vardnadshavare/inloggad2/he
|
|||
|
||||
export const navigationControllerScript = 'https://etjanst.stockholm.se/vardnadshavare/bundles/navigationController'
|
||||
|
||||
export const childcontrollerScript = 'https://etjanst.stockholm.se/vardnadshavare/bundles/childcontroller'
|
||||
export const childcontrollerScript = `https://etjanst.stockholm.se/vardnadshavare/bundles/childcontroller?v=${Date.now()}`
|
Loading…
Reference in New Issue