feat: add init url and start bankId session
This commit is contained in:
parent
e0adb9797b
commit
6289c43470
|
@ -0,0 +1,5 @@
|
|||
## Admentum API
|
||||
|
||||
To test
|
||||
|
||||
nx serve api-test-app --args=1212121212,admentum
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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`
|
||||
|
|
Loading…
Reference in New Issue