Package Exports
- @alaan/s2s-auth
- @alaan/s2s-auth/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@alaan/s2s-auth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@alaan/s2s-auth
A lightweight NestJS library for service-to-service authentication using JWT (JSON Web Tokens).
Features
- Secure JWT-based authentication between microservices
- Customizable payload and expiration
Installation
npm install @alaan/s2s-authUsage
1. Initialize the S2SAuthModule
@Module({
imports: [S2SAuthModule.forRoot({secret:"secret-key", expiresIn: '1m'})],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}2. Add the Auth Guard to a controller
@Get()
@UseGuards(S2SJwtAuthGuard)
getHello(): string {
return this.appService.getHello();
}3. Generate the token through shared secret or a trusted Idp
s2sAuthService.createToken({serviceId: 'test-service', scope: 'read'});Configuration
secret: JWT signing/verification secret (required)expiresIn: expiry formatted as 1m for 1 minute, 2days etc (similar to jsonwebtoken)
Reporting Issues
If you encounter bugs or unexpected behavior:
- Check the issues page.
- Provide error messages, stack traces, and usage details.
- Include your Node.js and library version.
License
MIT