May 26, 2022

How to securing access to of Swagger with HTTP Basic Auth? With example if TypeScript NestJS.



- First set up NestJS TypeScrip basic project.

- Install express-basic-auth module using this command: npm i express-basic-auth

- import module on main.ts file

- Full example of main.ts file:


// import auth module

import * as basicAuth from 'express-basic-auth';

// Add HTTP Basic Auth

app.use(

    basicAuth({

        challenge: true,

        users: {

            defineUserName: 'passwrd here',

        },

    }),

);


// Main Code

const options = new DocumentBuilder()

    .setTitle('First App')

    .setSchemes('https')

    .setDescription('Firsy App API documentation')

    .setVersion('1.0')

    .build()


const document = SwaggerModule.createDocument(app, options)

SwaggerModule.setup('docs', app, document, {

    customSiteTitle: 'First App documentation',

});


Enjoy! 

Integrating Google reCAPTCHA v3 in HTML Form with PHP

  What is Google reCAPTCHA v3? Google reCAPTCHA is a free service that helps protect websites from spam and abuse. reCAPTCHA v3 is the lates...