diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-22 17:16:32 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-05-22 17:16:32 -0700 |
commit | 8940df7dd71d562ca9a52bc8e17a677dd9679e85 (patch) | |
tree | c645765e481a9aa8072adf4d1c992784bb62665e | |
parent | 94890bc86051af268f1a1d8e2315f8238a7e3a64 (diff) |
Verify the assertion and return a response
-rw-r--r-- | example/index.js | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/example/index.js b/example/index.js index e47023d..c9ac80e 100644 --- a/example/index.js +++ b/example/index.js @@ -111,7 +111,27 @@ app.get('/generate-assertion-options', (req, res) => { app.post('/verify-assertion', (req, res) => { const { body } = req; - console.log('verifying assertion:', body); + let dbAuthenticator; + // "Query the DB" here for an authenticator matching `base64CredentialID` + Object.values(inMemoryUserDeviceDB).forEach((userDevs) => { + for(let dev of userDevs) { + if (dev.base64CredentialID === body.base64CredentialID) { + dbAuthenticator = dev; + return; + } + } + }); + + const verification = verifyAssertionResponse(body, `https://${origin}`, dbAuthenticator); + + const { verified, authenticatorInfo } = verification; + + if (verified) { + // Update the authenticator's counter in the DB to the newest count in the assertion + dbAuthenticator.counter = authenticatorInfo.counter; + } + + res.send({ verified }) }); https.createServer({ |