feat: bankId login almost working

This commit is contained in:
Christian Landgren 2023-09-14 11:48:26 +02:00
parent 6289c43470
commit 58a0ed9825
3 changed files with 42 additions and 23 deletions

View File

@ -286,17 +286,26 @@ export class ApiAdmentum extends EventEmitter implements Api {
return this.fakeMode()
this.isFake = false
const sessionId = await this.fetch('get-session', bankIdSessionUrl(''))
.then((res) => {
console.log('got res', res, (res as any).url)
const url = await this.fetch('get-session', bankIdSessionUrl('')).then(
(res) => {
console.log('got res', res, (res as any).url, res.headers)
return (res as any).url
})
.then((url) => url.split('=').pop()) // https://login.grandid.com/?sessionid=234324
}
)
await this.fetch('get-cookies', url)
// https://login.grandid.com/?sessionid=234324
// => 234324
const sessionId = url.split('=').pop()
if (!sessionId) throw new Error('No session provided')
console.log('url', bankIdInitUrl(sessionId))
this.fetch('bankid-init', bankIdInitUrl(sessionId), {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'ssn=' + personalNumber,
})

View File

@ -21,23 +21,33 @@ export class GrandidChecker extends EventEmitter implements LoginStatusChecker {
}
async check(): Promise<void> {
// try {
// console.log('polling bankid signature')
// // https://mNN-mg-local.idp.funktionstjanster.se/mg-local/auth/ccp11/grp/pollstatus
// if (true)
// this.emit('OK')
// } else if (isError) {
// console.log('polling error')
// this.emit('ERROR')
// } else if (!this.cancelled && keepPolling) {
// console.log('keep on polling...')
// this.emit('PENDING')
// setTimeout(() => this.check(), 3000)
// }
// } catch (er) {
// console.log('Error validating login to Hjärntorget', er)
// this.emit('ERROR')
// }
try {
console.log('polling bankid signature', this.basePollingUrl)
const result = await this.fetcher(
'bankid-checker',
bankIdCheckUrl(this.basePollingUrl)
).then((res) => {
console.log('checker response', res)
return res.text()
})
console.log('bankid result', result)
const ok = result.includes('OK')
const isError = result.includes('Unauthorized')
// https://mNN-mg-local.idp.funktionstjanster.se/mg-local/auth/ccp11/grp/pollstatus
if (ok) {
this.emit('OK')
} else if (isError) {
console.log('polling error')
this.emit('ERROR')
} else if (!this.cancelled) {
console.log('keep on polling...')
this.emit('PENDING')
setTimeout(() => this.check(), 3000)
}
} catch (err) {
console.log('Error validating login to Hjärntorget', err)
this.emit('ERROR')
}
}
async cancel(): Promise<void> {

View File

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