11import * as client from './index.js'
22
3- import type { PrivateKey } from 'oauth4webapi'
43import type * as express from 'express'
54import type passport from 'passport'
65
@@ -29,6 +28,8 @@ export interface AuthenticateOptions extends passport.AuthenticateOptions {
2928 * authorization request or token endpoint request, depending on whether it's
3029 * part of {@link Strategy.authenticate} options during the initial redirect or
3130 * callback phase.
31+ *
32+ * This is a request-specific override for {@link StrategyOptions.resource}.
3233 */
3334 resource ?: string | string [ ]
3435
@@ -47,6 +48,9 @@ export interface AuthenticateOptions extends passport.AuthenticateOptions {
4748 /**
4849 * OAuth 2.0 Rich Authorization Requests to use for the authorization request.
4950 * It is ignored for token endpoint requests.
51+ *
52+ * This is a request-specific override for
53+ * {@link StrategyOptions.authorizationDetails}.
5054 */
5155 authorizationDetails ?:
5256 | client . AuthorizationDetails
@@ -61,6 +65,8 @@ export interface AuthenticateOptions extends passport.AuthenticateOptions {
6165 /**
6266 * OAuth 2.0 scope to use for the authorization request. It is ignored for
6367 * token endpoint requests.
68+ *
69+ * This is a request-specific override for {@link StrategyOptions.scope}.
6470 */
6571 scope ?: string | string [ ]
6672
@@ -98,22 +104,26 @@ interface StrategyOptionsBase {
98104 * Openid-client Configuration instance.
99105 */
100106 config : client . Configuration
107+
101108 /**
102109 * Name of the strategy, default is the host component of the authorization
103110 * server's issuer identifier.
104111 */
105112 name ?: string
113+
106114 /**
107115 * Property in the session to use for storing the authorization request state,
108116 * default is the host component of the authorization server's issuer
109117 * identifier.
110118 */
111119 sessionKey ?: string
120+
112121 /**
113122 * Function used to retrieve an openid-client DPoPHandle for a given request,
114123 * when provided the strategy will use DPoP where applicable.
115124 */
116125 DPoP ?: getDPoPHandle
126+
117127 /**
118128 * An absolute URL to which the authorization server will redirect the user
119129 * after obtaining authorization. The {@link !URL} instance's `href` will be
@@ -122,11 +132,13 @@ interface StrategyOptionsBase {
122132 * {@link URL} instance.
123133 */
124134 callbackURL ?: URL | string
135+
125136 /**
126137 * OAuth 2.0 Authorization Request Scope. This will be used as the `scope`
127138 * authorization request parameter unless specified through other means.
128139 */
129140 scope ?: string
141+
130142 /**
131143 * OAuth 2.0 Rich Authorization Request(s). This will be used as the
132144 * `authorization_details` authorization request parameter unless specified
@@ -135,15 +147,18 @@ interface StrategyOptionsBase {
135147 authorizationDetails ?:
136148 | client . AuthorizationDetails
137149 | client . AuthorizationDetails [ ]
150+
138151 /**
139152 * OAuth 2.0 Resource Indicator(s). This will be used as the `resource`
140153 * authorization request parameter unless specified through other means.
141154 */
142155 resource ?: string | string [ ]
156+
143157 /**
144158 * Whether the strategy will use PAR. Default is `false`.
145159 */
146160 usePAR ?: boolean
161+
147162 /**
148163 * Whether the strategy will use JAR. Its value can be a private key to sign
149164 * with or an array with the private key and a modify assertion function that
@@ -153,8 +168,9 @@ interface StrategyOptionsBase {
153168 useJAR ?:
154169 | false
155170 | client . CryptoKey
156- | PrivateKey
157- | [ client . CryptoKey | PrivateKey , client . ModifyAssertionFunction ]
171+ | client . PrivateKey
172+ | [ client . CryptoKey | client . PrivateKey , client . ModifyAssertionFunction ]
173+
158174 /**
159175 * Whether the verify function should get the `req` as first argument instead.
160176 * Default is `false`.
@@ -200,7 +216,7 @@ export class Strategy implements passport.Strategy {
200216 /**
201217 * @internal
202218 */
203- _config : client . Configuration
219+ _config : StrategyOptionsBase [ 'config' ]
204220 /**
205221 * @internal
206222 */
@@ -212,27 +228,27 @@ export class Strategy implements passport.Strategy {
212228 /**
213229 * @internal
214230 */
215- _sessionKey : string
231+ _sessionKey : NonNullable < StrategyOptionsBase [ 'sessionKey' ] >
216232 /**
217233 * @internal
218234 */
219- _passReqToCallback ?: boolean
235+ _passReqToCallback : StrategyOptionsBase [ 'passReqToCallback' ]
220236 /**
221237 * @internal
222238 */
223- _usePAR ?: boolean
239+ _usePAR : StrategyOptionsBase [ 'usePAR' ]
224240 /**
225241 * @internal
226242 */
227- _useJAR ? : StrategyOptionsBase [ 'useJAR' ]
243+ _useJAR : StrategyOptionsBase [ 'useJAR' ]
228244 /**
229245 * @internal
230246 */
231- _DPoP ? : StrategyOptionsBase [ 'DPoP' ]
247+ _DPoP : StrategyOptionsBase [ 'DPoP' ]
232248 /**
233249 * @internal
234250 */
235- _scope ?: string
251+ _scope : StrategyOptionsBase [ 'scope' ]
236252 /**
237253 * @internal
238254 */
@@ -278,7 +294,24 @@ export class Strategy implements passport.Strategy {
278294 }
279295
280296 /**
281- * Return extra parameters to be included an authorization request.
297+ * [Strategy method] Return additional authorization request parameters.
298+ *
299+ * This method is intended to be overloaded if additional parameters need to
300+ * be included an authorization request are needed.
301+ *
302+ * By default this method takes care of adding the corresponding authorization
303+ * endpoint parameters when
304+ * {@link AuthenticateOptions.authorizationDetails authorizationDetails},
305+ * {@link AuthenticateOptions.idTokenHint idTokenHint},
306+ * {@link AuthenticateOptions.loginHint loginHint},
307+ * {@link AuthenticateOptions.prompt prompt},
308+ * {@link AuthenticateOptions.resource resource}, or
309+ * {@link AuthenticateOptions.scope scope} properties of
310+ * {@link AuthenticateOptions} are used.
311+ *
312+ * @param req
313+ * @param options This is the value originally passed to
314+ * `passport.authenticate()` as its `options` argument.
282315 */
283316 authorizationRequestParams < TOptions extends AuthenticateOptions > (
284317 // @ts -ignore
@@ -323,8 +356,18 @@ export class Strategy implements passport.Strategy {
323356 }
324357
325358 /**
326- * Return extra parameters to be included in the authorization code grant
327- * token endpoint request.
359+ * [Strategy method] Return additional token endpoint request parameters.
360+ *
361+ * This method is intended to be overloaded if additional parameters to be
362+ * included in the authorization code grant token endpoint request are
363+ * needed.
364+ *
365+ * By default this method takes care of adding the `resource` token endpoint
366+ * parameters when {@link AuthenticateOptions.resource} is used.
367+ *
368+ * @param req
369+ * @param options This is the value originally passed to
370+ * `passport.authenticate()` as its `options` argument.
328371 */
329372 authorizationCodeGrantParameters < TOptions extends AuthenticateOptions > (
330373 // @ts -ignore
@@ -341,6 +384,8 @@ export class Strategy implements passport.Strategy {
341384 }
342385
343386 /**
387+ * @private
388+ *
344389 * @internal
345390 */
346391 async authorizationRequest < TOptions extends AuthenticateOptions > (
@@ -458,6 +503,8 @@ export class Strategy implements passport.Strategy {
458503 }
459504
460505 /**
506+ * @private
507+ *
461508 * @internal
462509 */
463510 async authorizationCodeGrant < TOptions extends AuthenticateOptions > (
@@ -500,6 +547,7 @@ export class Strategy implements passport.Strategy {
500547 } ,
501548 new Headers ( ) ,
502549 ) ,
550+ // @ts -ignore
503551 body : req ,
504552 duplex : 'half' ,
505553 } )
@@ -561,13 +609,29 @@ export class Strategy implements passport.Strategy {
561609 * {@link StrategyOptionsBase.callbackURL} are used in which case those are
562610 * used as the `redirect_uri` parameter instead.
563611 *
612+ * Default is
613+ *
614+ * ```ts
615+ * function currentUrl(req: express.Request): URL {
616+ * return new URL(
617+ * `${req.protocol}://${req.host}${req.originalUrl ?? req.url}`,
618+ * )
619+ * }
620+ * ```
621+ *
622+ * When behind a reverse proxy it assumes common proxy headers are in use and
623+ * that
624+ * {@link https://expressjs.com/en/guide/behind-proxies.html Express (behind proxies docs)},
625+ * or
626+ * {@link https://fastify.dev/docs/latest/Reference/Server/#trustproxy Fastify (trustProxy docs)}
627+ * are properly configured to trust them.
564628 */
565629 currentUrl ( req : express . Request ) : URL {
566630 return new URL ( `${ req . protocol } ://${ req . host } ${ req . originalUrl ?? req . url } ` )
567631 }
568632
569633 /**
570- * Authenticate request.
634+ * [Passport method] Authenticate the request.
571635 */
572636 authenticate < TOptions extends AuthenticateOptions > (
573637 this : passport . StrategyCreated <
0 commit comments