Skip to content

Commit

Permalink
fix: 🐛 Fix för login block 24mars
Browse files Browse the repository at this point in the history
Denna gör så att bl.a. x-xsrf-token7 fungerar samt lägger till
cachebusting parameter på childcontroller
  • Loading branch information
kajetan-kazimierczak committed Mar 24, 2021
1 parent 52ba372 commit 7667a5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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> {
Expand All @@ -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
}
})

Expand Down
2 changes: 1 addition & 1 deletion lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`

0 comments on commit 7667a5e

Please sign in to comment.