Skip to content

Commit e9f232d

Browse files
authored
🤖 Merge PR DefinitelyTyped#73561 [passport-http-bearer] make done callback info.scope property optional by @chriskrycho
1 parent 3894c57 commit e9f232d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎types/passport-http-bearer/index.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface IStrategyOptions {
1313
}
1414
interface IVerifyOptions {
1515
message?: string | undefined;
16-
scope: string | string[];
16+
scope?: string | string[];
1717
}
1818

1919
interface VerifyFunction {

‎types/passport-http-bearer/passport-http-bearer-tests.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ passport.use(
6666
}),
6767
);
6868

69+
// Allow *not* passing `scope`, because is merely conventional.
70+
passport.use(
71+
new httpBearer.Strategy(
72+
(token: string, done: (error: unknown, user: unknown, options?: httpBearer.IVerifyOptions) => void) => {
73+
done(null, {}, {/* no values is technically fine! */});
74+
done(null, {}, { message: "so is just having a message" });
75+
},
76+
),
77+
);
78+
79+
// Allow arbitrary additional data on the `info` object
80+
interface ExtraOptions extends httpBearer.IVerifyOptions {
81+
arbitraryData: string;
82+
}
83+
84+
type ExtendedDoneFn = (error: unknown, user: unknown, options?: ExtraOptions) => void;
85+
86+
passport.use(
87+
new httpBearer.Strategy((token: string, done: ExtendedDoneFn) => {
88+
done(null, {}, {
89+
arbitraryData: "can go here",
90+
});
91+
}),
92+
);
93+
6994
let app = express();
7095
app.post("/login", passport.authenticate("bearer", { failureRedirect: "/login" }), function(req, res) {
7196
res.redirect("/");

0 commit comments

Comments
 (0)