diff options
author | Matthew Miller <matthew@millerti.me> | 2020-11-16 10:50:04 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-11-16 10:50:04 -0800 |
commit | 95b217f7c7fe73708c9a29c99438d5bd58d27f3d (patch) | |
tree | 29f4b84b31837742e941c8737873a690a2d4eb90 | |
parent | 3b4c7a05ce0b43aeff7d5be96f130714fd09002c (diff) |
Move LoggedInUser type to .d.ts file
-rw-r--r-- | example/example-server.d.ts | 38 | ||||
-rw-r--r-- | example/index.ts | 40 |
2 files changed, 40 insertions, 38 deletions
diff --git a/example/example-server.d.ts b/example/example-server.d.ts new file mode 100644 index 0000000..c131310 --- /dev/null +++ b/example/example-server.d.ts @@ -0,0 +1,38 @@ +import type { AuthenticatorDevice } from '@simplewebauthn/typescript-types'; + +/** + * You'll need a database to store a few things: + * + * 1. Users + * + * You'll need to be able to associate attestation and assertions challenges, and authenticators to + * a specific user + * + * 2. Challenges + * + * The totally-random-unique-every-time values you pass into every execution of + * `generateAttestationOptions()` or `generateAssertionOptions()` MUST be stored until + * `verifyAttestationResponse()` or `verifyAssertionResponse()` (respectively) is called to verify + * that the response contains the signed challenge. + * + * These values only need to be persisted for `timeout` number of milliseconds (see the `generate` + * methods and their optional `timeout` parameter) + * + * 3. Authenticator Devices + * + * After an attestation, you'll need to store three things about the authenticator: + * + * - Base64-encoded "Credential ID" (varchar) + * - Base64-encoded "Public Key" (varchar) + * - Counter (int) + * + * Each authenticator must also be associated to a user so that you can generate a list of + * authenticator credential IDs to pass into `generateAssertionOptions()`, from which one is + * expected to generate an assertion response. + */ +interface LoggedInUser { + id: string; + username: string; + devices: AuthenticatorDevice[]; + currentChallenge?: string; +} diff --git a/example/index.ts b/example/index.ts index cb587ae..6aebe2b 100644 --- a/example/index.ts +++ b/example/index.ts @@ -18,7 +18,8 @@ import { generateAssertionOptions, verifyAssertionResponse, } from '@simplewebauthn/server'; -import type { AuthenticatorDevice } from '@simplewebauthn/typescript-types'; + +import { LoggedInUser } from './example-server'; const app = express(); const host = '0.0.0.0'; @@ -52,43 +53,6 @@ const expectedOrigin = `https://${rpID}`; */ const loggedInUserId = 'internalUserId'; -/** - * You'll need a database to store a few things: - * - * 1. Users - * - * You'll need to be able to associate attestation and assertions challenges, and authenticators to - * a specific user - * - * 2. Challenges - * - * The totally-random-unique-every-time values you pass into every execution of - * `generateAttestationOptions()` or `generateAssertionOptions()` MUST be stored until - * `verifyAttestationResponse()` or `verifyAssertionResponse()` (respectively) is called to verify - * that the response contains the signed challenge. - * - * These values only need to be persisted for `timeout` number of milliseconds (see the `generate` - * methods and their optional `timeout` parameter) - * - * 3. Authenticator Devices - * - * After an attestation, you'll need to store three things about the authenticator: - * - * - Base64-encoded "Credential ID" (varchar) - * - Base64-encoded "Public Key" (varchar) - * - Counter (int) - * - * Each authenticator must also be associated to a user so that you can generate a list of - * authenticator credential IDs to pass into `generateAssertionOptions()`, from which one is - * expected to generate an assertion response. - */ -interface LoggedInUser { - id: string; - username: string; - devices: AuthenticatorDevice[]; - currentChallenge?: string; -} - const inMemoryUserDeviceDB: { [loggedInUserId: string]: LoggedInUser } = { [loggedInUserId]: { id: loggedInUserId, |