|
1 |
| -import { FastifyPluginCallback, FastifyReply, FastifyRequest, FastifyInstance } from 'fastify'; |
2 |
| -import { CookieSerializeOptions } from "@fastify/cookie"; |
| 1 | +import { FastifyPluginCallback, FastifyReply, FastifyRequest, FastifyInstance } from 'fastify' |
| 2 | +import { CookieSerializeOptions } from '@fastify/cookie' |
3 | 3 |
|
4 | 4 | interface FastifyOauth2 extends FastifyPluginCallback<fastifyOauth2.FastifyOAuth2Options> {
|
5 |
| - APPLE_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
6 |
| - DISCORD_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
7 |
| - FACEBOOK_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
8 |
| - GITHUB_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
9 |
| - GITLAB_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
10 |
| - LINKEDIN_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
11 |
| - GOOGLE_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
12 |
| - MICROSOFT_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
13 |
| - SPOTIFY_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
14 |
| - VKONTAKTE_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
15 |
| - TWITCH_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
16 |
| - VATSIM_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
17 |
| - VATSIM_DEV_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
18 |
| - EPIC_GAMES_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
19 |
| - YANDEX_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 5 | + APPLE_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 6 | + DISCORD_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 7 | + FACEBOOK_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 8 | + GITHUB_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 9 | + GITLAB_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 10 | + LINKEDIN_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 11 | + GOOGLE_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 12 | + MICROSOFT_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 13 | + SPOTIFY_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 14 | + VKONTAKTE_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 15 | + TWITCH_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 16 | + VATSIM_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 17 | + VATSIM_DEV_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 18 | + EPIC_GAMES_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
| 19 | + YANDEX_CONFIGURATION: fastifyOauth2.ProviderConfiguration; |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | declare namespace fastifyOauth2 {
|
@@ -50,163 +50,163 @@ declare namespace fastifyOauth2 {
|
50 | 50 | verifierCookieName?: string;
|
51 | 51 | }
|
52 | 52 |
|
53 |
| - export type TToken = 'access_token' | 'refresh_token' |
| 53 | + export type TToken = 'access_token' | 'refresh_token' |
54 | 54 |
|
55 |
| - export interface Token { |
56 |
| - token_type: 'Bearer'; |
57 |
| - access_token: string; |
58 |
| - refresh_token?: string; |
59 |
| - id_token?: string; |
60 |
| - expires_in: number; |
61 |
| - expires_at: Date; |
62 |
| - } |
| 55 | + export interface Token { |
| 56 | + token_type: 'Bearer'; |
| 57 | + access_token: string; |
| 58 | + refresh_token?: string; |
| 59 | + id_token?: string; |
| 60 | + expires_in: number; |
| 61 | + expires_at: Date; |
| 62 | + } |
63 | 63 |
|
64 |
| - export interface OAuth2Token { |
65 |
| - /** |
| 64 | + export interface OAuth2Token { |
| 65 | + /** |
66 | 66 | * Immutable object containing the token object provided while constructing a new access token instance.
|
67 | 67 | * This property will usually have the schema as specified by RFC6750,
|
68 | 68 | * but the exact properties may vary between authorization servers.
|
69 | 69 | */
|
70 |
| - token: Token; |
| 70 | + token: Token; |
71 | 71 |
|
72 |
| - /** |
| 72 | + /** |
73 | 73 | * Determines if the current access token is definitely expired or not
|
74 | 74 | * @param expirationWindowSeconds Window of time before the actual expiration to refresh the token. Defaults to 0.
|
75 | 75 | */
|
76 |
| - expired(expirationWindowSeconds?: number): boolean; |
77 |
| - |
78 |
| - /** Refresh the access token */ |
79 |
| - refresh(params?: {}): Promise<OAuth2Token>; |
80 |
| - |
81 |
| - /** Revoke access or refresh token */ |
82 |
| - revoke(tokenType: 'access_token' | 'refresh_token'): Promise<void>; |
83 |
| - |
84 |
| - /** Revoke both the existing access and refresh tokens */ |
85 |
| - revokeAll(): Promise<void>; |
86 |
| - } |
87 |
| - |
88 |
| - export interface ProviderConfiguration { |
89 |
| - /** String used to set the host to request the tokens to. Required. */ |
90 |
| - tokenHost: string; |
91 |
| - /** String path to request an access token. Default to /oauth/token. */ |
92 |
| - tokenPath?: string | undefined; |
93 |
| - /** String path to revoke an access token. Default to /oauth/revoke. */ |
94 |
| - revokePath?: string | undefined; |
95 |
| - /** String used to set the host to request an "authorization code". Default to the value set on auth.tokenHost. */ |
96 |
| - authorizeHost?: string | undefined; |
97 |
| - /** String path to request an authorization code. Default to /oauth/authorize. */ |
98 |
| - authorizePath?: string | undefined; |
99 |
| - } |
100 |
| - |
101 |
| - export interface Credentials { |
102 |
| - client: { |
103 |
| - /** Service registered client id. Required. */ |
104 |
| - id: string; |
105 |
| - /** Service registered client secret. Required. */ |
106 |
| - secret: string; |
107 |
| - /** Parameter name used to send the client secret. Default to client_secret. */ |
108 |
| - secretParamName?: string | undefined; |
109 |
| - /** Parameter name used to send the client id. Default to client_id. */ |
110 |
| - idParamName?: string | undefined; |
111 |
| - }; |
112 |
| - auth?: ProviderConfiguration; |
113 |
| - /** |
| 76 | + expired(expirationWindowSeconds?: number): boolean; |
| 77 | + |
| 78 | + /** Refresh the access token */ |
| 79 | + refresh(params?: {}): Promise<OAuth2Token>; |
| 80 | + |
| 81 | + /** Revoke access or refresh token */ |
| 82 | + revoke(tokenType: 'access_token' | 'refresh_token'): Promise<void>; |
| 83 | + |
| 84 | + /** Revoke both the existing access and refresh tokens */ |
| 85 | + revokeAll(): Promise<void>; |
| 86 | + } |
| 87 | + |
| 88 | + export interface ProviderConfiguration { |
| 89 | + /** String used to set the host to request the tokens to. Required. */ |
| 90 | + tokenHost: string; |
| 91 | + /** String path to request an access token. Default to /oauth/token. */ |
| 92 | + tokenPath?: string | undefined; |
| 93 | + /** String path to revoke an access token. Default to /oauth/revoke. */ |
| 94 | + revokePath?: string | undefined; |
| 95 | + /** String used to set the host to request an "authorization code". Default to the value set on auth.tokenHost. */ |
| 96 | + authorizeHost?: string | undefined; |
| 97 | + /** String path to request an authorization code. Default to /oauth/authorize. */ |
| 98 | + authorizePath?: string | undefined; |
| 99 | + } |
| 100 | + |
| 101 | + export interface Credentials { |
| 102 | + client: { |
| 103 | + /** Service registered client id. Required. */ |
| 104 | + id: string; |
| 105 | + /** Service registered client secret. Required. */ |
| 106 | + secret: string; |
| 107 | + /** Parameter name used to send the client secret. Default to client_secret. */ |
| 108 | + secretParamName?: string | undefined; |
| 109 | + /** Parameter name used to send the client id. Default to client_id. */ |
| 110 | + idParamName?: string | undefined; |
| 111 | + }; |
| 112 | + auth?: ProviderConfiguration; |
| 113 | + /** |
114 | 114 | * Used to set global options to the internal http library (wreck).
|
115 | 115 | * All options except baseUrl are allowed
|
116 | 116 | * Defaults to header.Accept = "application/json"
|
117 | 117 | */
|
118 |
| - http?: {} | undefined; |
119 |
| - options?: { |
120 |
| - /** Format of data sent in the request body. Defaults to form. */ |
121 |
| - bodyFormat?: "json" | "form" | undefined; |
122 |
| - /** |
| 118 | + http?: {} | undefined; |
| 119 | + options?: { |
| 120 | + /** Format of data sent in the request body. Defaults to form. */ |
| 121 | + bodyFormat?: 'json' | 'form' | undefined; |
| 122 | + /** |
123 | 123 | * Indicates the method used to send the client.id/client.secret authorization params at the token request.
|
124 | 124 | * If set to body, the bodyFormat option will be used to format the credentials.
|
125 | 125 | * Defaults to header
|
126 | 126 | */
|
127 |
| - authorizationMethod?: "header" | "body" | undefined; |
128 |
| - } | undefined; |
129 |
| - } |
130 |
| - |
131 |
| - export interface OAuth2Namespace { |
132 |
| - getAccessTokenFromAuthorizationCodeFlow( |
133 |
| - request: FastifyRequest, |
134 |
| - ): Promise<OAuth2Token>; |
135 |
| - |
136 |
| - getAccessTokenFromAuthorizationCodeFlow( |
137 |
| - request: FastifyRequest, |
138 |
| - reply: FastifyReply, |
139 |
| - ): Promise<OAuth2Token>; |
140 |
| - |
141 |
| - getAccessTokenFromAuthorizationCodeFlow( |
142 |
| - request: FastifyRequest, |
143 |
| - callback: (err: any, token: OAuth2Token) => void, |
144 |
| - ): void; |
145 |
| - |
146 |
| - getAccessTokenFromAuthorizationCodeFlow( |
147 |
| - request: FastifyRequest, |
148 |
| - reply: FastifyReply, |
149 |
| - callback: (err: any, token: OAuth2Token) => void, |
150 |
| - ): void; |
151 |
| - |
152 |
| - getNewAccessTokenUsingRefreshToken( |
153 |
| - refreshToken: Token, |
154 |
| - params: Object, |
155 |
| - callback: (err: any, token: OAuth2Token) => void, |
156 |
| - ): void; |
157 |
| - |
158 |
| - getNewAccessTokenUsingRefreshToken(refreshToken: Token, params: Object): Promise<OAuth2Token>; |
159 |
| - |
160 |
| - generateAuthorizationUri( |
161 |
| - request: FastifyRequest, |
162 |
| - reply: FastifyReply, |
163 |
| - callback: (err: any, uri: string) => void |
164 |
| - ): void |
165 |
| - |
166 |
| - generateAuthorizationUri( |
167 |
| - request: FastifyRequest, |
168 |
| - reply: FastifyReply, |
169 |
| - ): Promise<string>; |
170 |
| - |
171 |
| - revokeToken( |
172 |
| - revokeToken: Token, |
173 |
| - tokenType: TToken, |
174 |
| - httpOptions: Object | undefined, |
175 |
| - callback: (err: any) => void |
176 |
| - ): void; |
177 |
| - |
178 |
| - revokeToken(revokeToken: Token, tokenType: TToken, httpOptions: Object | undefined): Promise<void>; |
179 |
| - |
180 |
| - revokeAllToken( |
181 |
| - revokeToken: Token, |
182 |
| - httpOptions: Object | undefined, |
183 |
| - callback: (err: any) => void |
184 |
| - ): void; |
185 |
| - |
186 |
| - revokeAllToken(revokeToken: Token, httpOptions: Object | undefined): Promise<void>; |
187 |
| - |
188 |
| - userinfo(tokenSetOrToken: Token | string): Promise<Object>; |
189 |
| - |
190 |
| - userinfo(tokenSetOrToken: Token | string, userInfoExtraOptions: UserInfoExtraOptions | undefined): Promise<Object>; |
191 |
| - |
192 |
| - userinfo(tokenSetOrToken: Token | string, callback: (err: any, userinfo: Object) => void): void; |
193 |
| - |
194 |
| - userinfo(tokenSetOrToken: Token | string, userInfoExtraOptions: UserInfoExtraOptions | undefined, callback: (err: any, userinfo: Object) => void): void; |
195 |
| - } |
196 |
| - export type UserInfoExtraOptions = { method?: 'GET' | 'POST', via?: 'header' | 'body', params?: object }; |
197 |
| - export const fastifyOauth2: FastifyOauth2 |
198 |
| - export {fastifyOauth2 as default} |
| 127 | + authorizationMethod?: 'header' | 'body' | undefined; |
| 128 | + } | undefined; |
| 129 | + } |
| 130 | + |
| 131 | + export interface OAuth2Namespace { |
| 132 | + getAccessTokenFromAuthorizationCodeFlow( |
| 133 | + request: FastifyRequest, |
| 134 | + ): Promise<OAuth2Token>; |
| 135 | + |
| 136 | + getAccessTokenFromAuthorizationCodeFlow( |
| 137 | + request: FastifyRequest, |
| 138 | + reply: FastifyReply, |
| 139 | + ): Promise<OAuth2Token>; |
| 140 | + |
| 141 | + getAccessTokenFromAuthorizationCodeFlow( |
| 142 | + request: FastifyRequest, |
| 143 | + callback: (err: any, token: OAuth2Token) => void, |
| 144 | + ): void; |
| 145 | + |
| 146 | + getAccessTokenFromAuthorizationCodeFlow( |
| 147 | + request: FastifyRequest, |
| 148 | + reply: FastifyReply, |
| 149 | + callback: (err: any, token: OAuth2Token) => void, |
| 150 | + ): void; |
| 151 | + |
| 152 | + getNewAccessTokenUsingRefreshToken( |
| 153 | + refreshToken: Token, |
| 154 | + params: Object, |
| 155 | + callback: (err: any, token: OAuth2Token) => void, |
| 156 | + ): void; |
| 157 | + |
| 158 | + getNewAccessTokenUsingRefreshToken(refreshToken: Token, params: Object): Promise<OAuth2Token>; |
| 159 | + |
| 160 | + generateAuthorizationUri( |
| 161 | + request: FastifyRequest, |
| 162 | + reply: FastifyReply, |
| 163 | + callback: (err: any, uri: string) => void |
| 164 | + ): void |
| 165 | + |
| 166 | + generateAuthorizationUri( |
| 167 | + request: FastifyRequest, |
| 168 | + reply: FastifyReply, |
| 169 | + ): Promise<string>; |
| 170 | + |
| 171 | + revokeToken( |
| 172 | + revokeToken: Token, |
| 173 | + tokenType: TToken, |
| 174 | + httpOptions: Object | undefined, |
| 175 | + callback: (err: any) => void |
| 176 | + ): void; |
| 177 | + |
| 178 | + revokeToken(revokeToken: Token, tokenType: TToken, httpOptions: Object | undefined): Promise<void>; |
| 179 | + |
| 180 | + revokeAllToken( |
| 181 | + revokeToken: Token, |
| 182 | + httpOptions: Object | undefined, |
| 183 | + callback: (err: any) => void |
| 184 | + ): void; |
| 185 | + |
| 186 | + revokeAllToken(revokeToken: Token, httpOptions: Object | undefined): Promise<void>; |
| 187 | + |
| 188 | + userinfo(tokenSetOrToken: Token | string): Promise<Object>; |
| 189 | + |
| 190 | + userinfo(tokenSetOrToken: Token | string, userInfoExtraOptions: UserInfoExtraOptions | undefined): Promise<Object>; |
| 191 | + |
| 192 | + userinfo(tokenSetOrToken: Token | string, callback: (err: any, userinfo: Object) => void): void; |
| 193 | + |
| 194 | + userinfo(tokenSetOrToken: Token | string, userInfoExtraOptions: UserInfoExtraOptions | undefined, callback: (err: any, userinfo: Object) => void): void; |
| 195 | + } |
| 196 | + export type UserInfoExtraOptions = { method?: 'GET' | 'POST', via?: 'header' | 'body', params?: object } |
| 197 | + export const fastifyOauth2: FastifyOauth2 |
| 198 | + export { fastifyOauth2 as default } |
199 | 199 | }
|
200 | 200 |
|
201 |
| -declare function fastifyOauth2(...params: Parameters<FastifyOauth2>): ReturnType<FastifyOauth2> |
| 201 | +declare function fastifyOauth2 (...params: Parameters<FastifyOauth2>): ReturnType<FastifyOauth2> |
202 | 202 |
|
203 | 203 | export = fastifyOauth2
|
204 | 204 |
|
205 |
| -type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'; |
| 205 | +type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' |
206 | 206 |
|
207 | 207 | declare module 'fastify' {
|
208 |
| - interface FastifyInstance { |
209 |
| - // UpperCaseCharacters ensures that the name has at least one character in it + is a simple camel-case:ification |
210 |
| - [key: `oauth2${UpperCaseCharacters}${string}`]: fastifyOauth2.OAuth2Namespace | undefined; |
211 |
| - } |
| 208 | + interface FastifyInstance { |
| 209 | + // UpperCaseCharacters ensures that the name has at least one character in it + is a simple camel-case:ification |
| 210 | + [key: `oauth2${UpperCaseCharacters}${string}`]: fastifyOauth2.OAuth2Namespace | undefined; |
| 211 | + } |
212 | 212 | }
|
0 commit comments