-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
60 lines (50 loc) · 1.72 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { type FastifyJWTOptions, type VerifyPayloadType } from '@fastify/jwt'
import { type FastifyPluginCallback, type FastifyReply, type FastifyRequest } from 'fastify'
import { Agent } from 'http'
import { type URL, type UrlObject } from 'url'
// Copied over to avoid TypeScript compilation errors
// https://github.com/nearform/get-jwks/issues/309
type GetJwksOptions = {
max?: number
ttl?: number
issuersWhitelist?: string[]
providerDiscovery?: boolean
jwksPath?: string
agent?: Agent
timeout?: number
}
export interface JWTOptions extends FastifyJWTOptions {
namespace?: string
jwks?: boolean | GetJwksOptions
}
export interface WebhookOptions {
url: string | URL | UrlObject
}
export type CreateSession = (request?: FastifyRequest, reply?: FastifyReply) => Promise<void>
export interface AuthStrategy {
name: string,
createSession: CreateSession
}
export interface FastifyUserPluginOptions {
jwt?: JWTOptions
webhook?: WebhookOptions
authStrategies?: AuthStrategy[]
}
export type AddAuthStrategyDecorator = (strategy: AuthStrategy) => void
export type ExtractUserDecorator = () => Promise<any>
export type CreateSessionDecorator = () => Promise<void>
export type CreateJWTSessionDecorator = () => Promise<VerifyPayloadType>
export type CreateWebhookSessionDecorator = () => Promise<void>
declare module 'fastify' {
interface FastifyInstance {
addAuthStrategy: AddAuthStrategyDecorator
}
interface FastifyRequest {
extractUser: ExtractUserDecorator
createSession: CreateSessionDecorator
createJWTSession: CreateJWTSessionDecorator
createWebhookSession: CreateWebhookSessionDecorator
}
}
declare const fastifyUser: FastifyPluginCallback<FastifyUserPluginOptions>
export default fastifyUser