Make temporary change to highlight cookie issue
This commit is contained in:
parent
1aaaeb64e3
commit
826b7453c4
|
@ -21,7 +21,7 @@ import { darkTheme, lightTheme } from './design/themes'
|
||||||
import useSettingsStorage from './hooks/useSettingsStorage'
|
import useSettingsStorage from './hooks/useSettingsStorage'
|
||||||
import { translations } from './utils/translation'
|
import { translations } from './utils/translation'
|
||||||
|
|
||||||
const apiSkolplattformen = initSkolplattformen(fetch, CookieManager)
|
//const apiSkolplattformen = initSkolplattformen(fetch, CookieManager)
|
||||||
const apiHjarntorget = initHjarntorget(fetch, CookieManager)
|
const apiHjarntorget = initHjarntorget(fetch, CookieManager)
|
||||||
|
|
||||||
const reporter = __DEV__
|
const reporter = __DEV__
|
||||||
|
@ -70,7 +70,7 @@ export default () => {
|
||||||
return (
|
return (
|
||||||
<SchoolPlatformProvider>
|
<SchoolPlatformProvider>
|
||||||
<ApiProvider
|
<ApiProvider
|
||||||
api={apiSkolplattformen}
|
api={apiHjarntorget}
|
||||||
storage={AsyncStorage}
|
storage={AsyncStorage}
|
||||||
reporter={reporter}
|
reporter={reporter}
|
||||||
>
|
>
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { toMarkdown, Api, URLSearchParams, LoginStatusChecker, CalendarItem,
|
||||||
Fetcher,
|
Fetcher,
|
||||||
FetcherOptions,
|
FetcherOptions,
|
||||||
wrap
|
wrap
|
||||||
} from '@skolplattformen/api'
|
} from '../../api/lib'
|
||||||
import { checkStatus } from './loginStatus'
|
import { checkStatus } from './loginStatus'
|
||||||
import { extractMvghostRequestBody, parseCalendarItem } from './parse/parsers'
|
import { extractMvghostRequestBody, parseCalendarItem } from './parse/parsers'
|
||||||
import {
|
import {
|
||||||
|
@ -89,6 +89,7 @@ export class ApiHjarntorget extends EventEmitter implements Api {
|
||||||
options?: FetcherOptions
|
options?: FetcherOptions
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.fetch = wrap(fetch, options);
|
this.fetch = wrap(fetch, options);
|
||||||
this.realFetcher = this.fetch;
|
this.realFetcher = this.fetch;
|
||||||
this.cookieManager = cookieManager
|
this.cookieManager = cookieManager
|
||||||
|
@ -427,7 +428,7 @@ export class ApiHjarntorget extends EventEmitter implements Api {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log("start polling")
|
console.log("start polling", (beginBankIdResponse as any).url)
|
||||||
|
|
||||||
const statusChecker = checkStatus(this.fetch, verifyUrlBase((beginBankIdResponse as any).url))
|
const statusChecker = checkStatus(this.fetch, verifyUrlBase((beginBankIdResponse as any).url))
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import { ApiHjarntorget } from './apiHjarntorget'
|
import { ApiHjarntorget } from './apiHjarntorget'
|
||||||
import { Api, FetcherOptions, Fetch, RNCookieManager,
|
import { FetcherOptions } from '../../api/lib/fetcher'
|
||||||
|
import { Fetch } from '../../api/lib/types'
|
||||||
|
import { Api } from '../../api/lib/api'
|
||||||
|
import { RNCookieManager,
|
||||||
ToughCookieJar,
|
ToughCookieJar,
|
||||||
wrapReactNativeCookieManager,
|
wrapReactNativeCookieManager,
|
||||||
wrapToughCookie } from '@skolplattformen/api'
|
wrapToughCookie } from '../../api/lib/cookies'
|
||||||
|
|
||||||
const init = (
|
const init = (
|
||||||
fetchImpl: Fetch,
|
fetchImpl: Fetch,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { LoginStatusChecker, Fetcher} from '@skolplattformen/api'
|
import { LoginStatusChecker, Fetcher} from '../../api/lib'
|
||||||
import {
|
import {
|
||||||
extractAuthGbgLoginRequestBody,
|
extractAuthGbgLoginRequestBody,
|
||||||
extractHjarntorgetSAMLLogin
|
extractHjarntorgetSAMLLogin
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as html from 'node-html-parser'
|
import * as html from 'node-html-parser'
|
||||||
import { decode } from 'he'
|
import { decode } from 'he'
|
||||||
import { CalendarItem } from '..'
|
|
||||||
|
|
||||||
// TODO: Move this into the parse folder and convert it to follow the pattern of other parsers (include tests).
|
// TODO: Move this into the parse folder and convert it to follow the pattern of other parsers (include tests).
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ function requestLogger(httpModule) {
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const { inspect } = require('util')
|
const { inspect } = require('util')
|
||||||
const init = require('./dist/api-hjarntorget/lib').default
|
const init = require('./dist/libs/api-hjarntorget/lib').default
|
||||||
|
|
||||||
const [, , personalNumber] = process.argv
|
const [, , personalNumber] = process.argv
|
||||||
|
|
||||||
|
@ -78,13 +78,13 @@ function requestLogger(httpModule) {
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const cookieJar = new CookieJar()
|
const cookieJar = new CookieJar()
|
||||||
const fetch = fetchCookie(nodeFetch, cookieJar)
|
const fetch = nodeFetch //fetchCookie(nodeFetch, cookieJar)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const api = init(fetch, cookieJar, { record })
|
const api = init(fetch, cookieJar, { record })
|
||||||
console.log("inited...")
|
console.log("inited...")
|
||||||
|
|
||||||
api.on('login', async () => {
|
api.on('login', async () => {
|
||||||
|
|
||||||
console.log("Loged in!")
|
console.log("Loged in!")
|
||||||
await api.getUser()
|
await api.getUser()
|
||||||
const children = await api.getChildren()
|
const children = await api.getChildren()
|
||||||
|
|
|
@ -98,21 +98,28 @@ export interface RNCookieManager {
|
||||||
export const wrapReactNativeCookieManager = (
|
export const wrapReactNativeCookieManager = (
|
||||||
rnc: RNCookieManager
|
rnc: RNCookieManager
|
||||||
): CookieManager => ({
|
): CookieManager => ({
|
||||||
clearAll: () => rnc.clearAll().then(),
|
clearAll: () => {
|
||||||
|
console.log("clearAll")
|
||||||
|
return rnc.clearAll().then()
|
||||||
|
},
|
||||||
getCookieString: async (url) => {
|
getCookieString: async (url) => {
|
||||||
const cookies = await rnc.get(url)
|
const cookies = await rnc.get(url)
|
||||||
|
console.log("getCookieString", url, cookies)
|
||||||
return Object.values(cookies)
|
return Object.values(cookies)
|
||||||
.map((c) => `${c.name}=${c.value}`)
|
.map((c) => `${c.name}=${c.value}`)
|
||||||
.join('; ')
|
.join('; ')
|
||||||
},
|
},
|
||||||
getCookies: async (url) => {
|
getCookies: async (url) => {
|
||||||
const cookies = await rnc.get(url)
|
const cookies = await rnc.get(url)
|
||||||
|
console.log("getCookies", url, cookies)
|
||||||
return Object.values(cookies)
|
return Object.values(cookies)
|
||||||
},
|
},
|
||||||
setCookie: async (cookie, url) => {
|
setCookie: async (cookie, url) => {
|
||||||
|
console.log("setting cookie", url, cookie)
|
||||||
await rnc.setFromResponse(url, serialize(cookie))
|
await rnc.setFromResponse(url, serialize(cookie))
|
||||||
},
|
},
|
||||||
setCookieString: async (cookieString, url) => {
|
setCookieString: async (cookieString, url) => {
|
||||||
|
console.log("setting cookieString", url, cookieString)
|
||||||
await rnc.setFromResponse(url, cookieString)
|
await rnc.setFromResponse(url, cookieString)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -66,7 +66,6 @@ export default function wrap(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const response = await fetch(url, config)
|
const response = await fetch(url, config)
|
||||||
|
|
||||||
const wrapMethod = (res: Response, methodName: string): void => {
|
const wrapMethod = (res: Response, methodName: string): void => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const original = res[methodName].bind(res)
|
const original = res[methodName].bind(res)
|
||||||
|
|
Loading…
Reference in New Issue