Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/passport-http-bearer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IStrategyOptions {
}
interface IVerifyOptions {
message?: string | undefined;
scope: string | string[];
scope?: string | string[];
}

interface VerifyFunction {
Expand Down
25 changes: 25 additions & 0 deletions types/passport-http-bearer/passport-http-bearer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
Expand Down