CSRF Token
Create and verify csrf tokens
Functions
TOC
const csrf =
create(secret [, saltLength [, callback]])
create(secret: string, saltLength?: number): Promise<string>
create(secret: string, saltLength: number, callback: (error: Error, token: string) => void): void
create(secret: string, callback: (error: Error, token: string) => void): void
secret
The secret to encrypt.saltLength
The length of the generated salt. Default:8
callback
A function with the generated token.- Returns void if callback is specified otherwise returns a promise with the generated token.
Create a CSRF token asynchronously.
csrfcsrf
createSync(secret, [saltLength])
createSync(secret: string, saltLength?: number): string
secret
The secret to encrypt.saltLength
The length of the generated salt. Default:8
- Returns the generated token.
Create a CSRF token synchronously.
const token = csrfconsole
verify(secret, token [, callback])
verify(secret: string, token: string): Promise<boolean>
verify(secret: string, token: string, callback: (matches: boolean) => void): void
secret
The secret that was supposadly encrypted.token
The token that hopefully is the secret in a encrypted form.callback
A function with the result of the verification.- Returns void if callback is specified otherwise returns a promise with the result of the verification.
Verify CSRF token asynchronously.
csrfcsrf
verifySync(secret, token)
verifySync(secret: string, token: string): boolean
secret
The secret that was supposadly encrypted.token
The token that hopefully is the secret in a encrypted form.- Returns a boolean if the match or not.
Verify CSRF token synchronously.
const matches = csrf if matches consoleelse console