feat: add init url and start bankId session

This commit is contained in:
Christian Landgren 2023-09-08 16:23:31 +02:00
parent e0adb9797b
commit 6289c43470
3 changed files with 26 additions and 5 deletions

View File

@ -0,0 +1,5 @@
## Admentum API
To test
nx serve api-test-app --args=1212121212,admentum

View File

@ -29,7 +29,12 @@ import * as html from 'node-html-parser'
import { fakeFetcher } from './fake/fakeFetcher'
import { checkStatus, DummyStatusChecker } from './loginStatus'
import { extractMvghostRequestBody, parseCalendarItem } from './parse/parsers'
import { bankIdInitUrl, bankIdCheckUrl, apiUrls } from './routes'
import {
bankIdInitUrl,
bankIdCheckUrl,
bankIdSessionUrl,
apiUrls,
} from './routes'
import parse from '@skolplattformen/curriculum'
function getDateOfISOWeek(week: number, year: number) {
@ -281,12 +286,20 @@ export class ApiAdmentum extends EventEmitter implements Api {
return this.fakeMode()
this.isFake = false
const sessionId = await this.fetch('init-session', bankIdInitUrl(''))
.then((res) => res.text())
.then((text) => /sessionsid=(.)/.exec(text)?.[0])
const sessionId = await this.fetch('get-session', bankIdSessionUrl(''))
.then((res) => {
console.log('got res', res, (res as any).url)
return (res as any).url
})
.then((url) => url.split('=').pop()) // https://login.grandid.com/?sessionid=234324
if (!sessionId) throw new Error('No session provided')
this.fetch('bankid-init', bankIdInitUrl(sessionId), {
method: 'POST',
body: 'ssn=' + personalNumber,
})
console.log('start polling', sessionId)
const statusChecker = checkStatus(this.fetch, bankIdCheckUrl(sessionId))

View File

@ -46,5 +46,8 @@ export const apiUrls = {
export const bankIdCheckUrl = (sessionId: string) =>
`https://login.grandid.com/?sessionid=${sessionId}&eleg=1&bankid=1`
export const bankIdInitUrl = (returnUrl: string) =>
export const bankIdSessionUrl = (returnUrl: string) =>
`https://auth.admentum.se/larande${returnUrl ? `?next=${returnUrl}` : ''}`
export const bankIdInitUrl = (sessionId: string) =>
`https://login.grandid.com/?sessionid=${sessionId}&eleg=1&bankid=1&bChoice=other`