|
3 | 3 | const fp = require('fastify-plugin') |
4 | 4 | const createError = require('@fastify/error') |
5 | 5 |
|
| 6 | +/** @typedef {import('./types/index').FastifyBasicAuthOptions} FastifyBasicAuthOptions */ |
| 7 | + |
6 | 8 | /** |
7 | 9 | * HTTP provides a simple challenge-response authentication framework |
8 | 10 | * that can be used by a server to challenge a client request and by a |
@@ -59,6 +61,7 @@ const controlRE = /[\x00-\x1F\x7F]/ |
59 | 61 |
|
60 | 62 | const userPassRE = /^([^:]*):(.*)$/ |
61 | 63 |
|
| 64 | +/** @type {typeof import('./types/index').fastifyBasicAuth} */ |
62 | 65 | async function fastifyBasicAuth (fastify, opts) { |
63 | 66 | if (typeof opts.validate !== 'function') { |
64 | 67 | throw new Error('Basic Auth: Missing validate function') |
@@ -144,6 +147,13 @@ async function fastifyBasicAuth (fastify, opts) { |
144 | 147 | } |
145 | 148 | } |
146 | 149 |
|
| 150 | +/** |
| 151 | + * Generates a function that returns the appropriate authentication header. |
| 152 | + * @param {FastifyBasicAuthOptions['authenticate']} authenticate - The authenticate option. |
| 153 | + * @param {FastifyBasicAuthOptions['utf8']} useUtf8 - Whether to use UTF-8 charset. |
| 154 | + * @param {FastifyBasicAuthOptions['proxyMode']} proxyMode - Whether in proxy mode. |
| 155 | + * @returns {(req: import('fastify').FastifyRequest) => false | [string, string]} Function that returns header tuple or false. |
| 156 | + */ |
147 | 157 | function getAuthenticateHeaders (authenticate, useUtf8, proxyMode) { |
148 | 158 | const defaultHeaderName = proxyMode ? 'Proxy-Authenticate' : 'WWW-Authenticate' |
149 | 159 | if (!authenticate) return () => false |
|
0 commit comments