2023-06-03 20:07:58 +02:00
|
|
|
## jwt
|
|
|
|
|
|
|
|
```ts
|
|
|
|
interface JwtPackage {
|
|
|
|
/**
|
|
|
|
* create a jwt signed token string
|
|
|
|
*
|
|
|
|
* @param claims data object
|
|
|
|
* @param options options (secret, validityDuration = expiry in X seconds)
|
|
|
|
*/
|
|
|
|
create(
|
|
|
|
claims: {
|
|
|
|
[key: string]: any
|
|
|
|
},
|
|
|
|
options?: {
|
|
|
|
secret?: string
|
|
|
|
validityDuration?: number
|
|
|
|
}
|
|
|
|
): string
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parse jwt token string
|
|
|
|
*
|
|
|
|
* @param token token string
|
|
|
|
* @param options options (secret)
|
|
|
|
*/
|
|
|
|
parse(
|
|
|
|
token: string,
|
|
|
|
options?: {
|
|
|
|
secret?: string
|
|
|
|
}
|
|
|
|
): {
|
|
|
|
error?: string
|
|
|
|
valid: boolean
|
|
|
|
method: {
|
|
|
|
Name: string
|
|
|
|
Hash: number
|
|
|
|
}
|
|
|
|
header: {
|
|
|
|
alg: string
|
|
|
|
typ: string
|
|
|
|
}
|
|
|
|
claims: {
|
|
|
|
exp?: number
|
|
|
|
[key: string]: any
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|