Merge pull request #90 from kolplattformen/fix/block200324

fix: 🐛 Fix för login block 24mars
This commit is contained in:
Erik Hellman 2021-03-24 21:17:07 +01:00 committed by GitHub
commit b611228ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -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
}
})

View File

@ -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()}`