diff --git a/types/passport-http-bearer/index.d.ts b/types/passport-http-bearer/index.d.ts index 7db5ba26d90e36..00b021dac98863 100644 --- a/types/passport-http-bearer/index.d.ts +++ b/types/passport-http-bearer/index.d.ts @@ -13,7 +13,7 @@ interface IStrategyOptions { } interface IVerifyOptions { message?: string | undefined; - scope: string | string[]; + scope?: string | string[]; } interface VerifyFunction { diff --git a/types/passport-http-bearer/passport-http-bearer-tests.ts b/types/passport-http-bearer/passport-http-bearer-tests.ts index b8dfd745046ed8..81c9a60dd455da 100644 --- a/types/passport-http-bearer/passport-http-bearer-tests.ts +++ b/types/passport-http-bearer/passport-http-bearer-tests.ts @@ -66,6 +66,31 @@ passport.use( }), ); +// Allow *not* passing `scope`, because is merely conventional. +passport.use( + new httpBearer.Strategy( + (token: string, done: (error: unknown, user: unknown, options?: httpBearer.IVerifyOptions) => void) => { + done(null, {}, {/* no values is technically fine! */}); + done(null, {}, { message: "so is just having a message" }); + }, + ), +); + +// Allow arbitrary additional data on the `info` object +interface ExtraOptions extends httpBearer.IVerifyOptions { + arbitraryData: string; +} + +type ExtendedDoneFn = (error: unknown, user: unknown, options?: ExtraOptions) => void; + +passport.use( + new httpBearer.Strategy((token: string, done: ExtendedDoneFn) => { + done(null, {}, { + arbitraryData: "can go here", + }); + }), +); + let app = express(); app.post("/login", passport.authenticate("bearer", { failureRedirect: "/login" }), function(req, res) { res.redirect("/");