@@ -34,6 +34,37 @@ const createServer = async (config: ExpressServerConfig, queue?: any) => {
3434 app . use ( cors ( ) ) ;
3535 const redis = await redisService ( ) ;
3636
37+ const auth = ( req : express . Request , res : express . Response , next : express . NextFunction ) => {
38+ if ( req . query . key === config . serverKey ) {
39+ return next ( ) ;
40+ }
41+ return res . json ( { message : "Invalid Key" } ) . status ( 401 ) ;
42+ } ;
43+
44+ // Basic Auth middleware for Bull Board
45+ const basicAuth = ( req : express . Request , res : express . Response , next : express . NextFunction ) => {
46+ const authHeader = req . headers . authorization ;
47+
48+ if ( ! authHeader ) {
49+ res . setHeader ( "WWW-Authenticate" , 'Basic realm="Bull Board Admin"' ) ;
50+ return res . status ( 401 ) . json ( { message : "Authentication required" } ) ;
51+ }
52+
53+ const auth = authHeader . split ( " " ) [ 1 ] ;
54+ const [ username , password ] = Buffer . from ( auth , "base64" ) . toString ( ) . split ( ":" ) ;
55+
56+ // Use config values or defaults for admin credentials
57+ const adminUsername = config . serverKey ;
58+ const adminPassword = config . serverKey ;
59+
60+ if ( username === adminUsername && password === adminPassword ) {
61+ return next ( ) ;
62+ }
63+
64+ res . setHeader ( "WWW-Authenticate" , 'Basic realm="Bull Board Admin"' ) ;
65+ return res . status ( 401 ) . json ( { message : "Invalid credentials" } ) ;
66+ } ;
67+
3768 // Set up Bull Board if queue is provided
3869 if ( queue ) {
3970 const serverAdapter = new ExpressAdapter ( ) ;
@@ -43,18 +74,11 @@ const createServer = async (config: ExpressServerConfig, queue?: any) => {
4374 } ) ;
4475
4576 serverAdapter . setBasePath ( "/admin/queues" ) ;
46- app . use ( "/admin/queues" , serverAdapter . getRouter ( ) ) ;
77+ app . use ( "/admin/queues" , basicAuth , serverAdapter . getRouter ( ) ) ;
4778
48- logger . info ( "Bull Board UI available at /admin/queues" ) ;
79+ logger . info ( "Bull Board UI available at /admin/queues (Basic Auth required) " ) ;
4980 }
5081
51- const auth = ( req : express . Request , res : express . Response , next : express . NextFunction ) => {
52- if ( req . query . key === config . serverKey ) {
53- return next ( ) ;
54- }
55- return res . json ( { message : "Invalid Key" } ) . status ( 401 ) ;
56- } ;
57-
5882 app . get ( "/salesforce/login" , ( req , res ) => {
5983 res . redirect ( jsForceOAuth2 . getAuthorizationUrl ( { scope : "api id web refresh_token" } ) ) ;
6084 } ) ;
0 commit comments