@alaan/s2s-auth
Version:
Reusable JWT auth module for NestJS service-to-service authentication
61 lines (41 loc) • 1.25 kB
Markdown
# @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
```bash
npm install @alaan/s2s-auth
```
## Usage
### 1. Initialize the S2SAuthModule
```ts
@Module({
imports: [S2SAuthModule.forRoot({secret:"secret-key", expiresIn: '1m'})],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
```
### 2. Add the Auth Guard to a controller
```ts
@Get()
@UseGuards(S2SJwtAuthGuard)
getHello(): string {
return this.appService.getHello();
}
```
### 3. Generate the token through shared secret or a trusted Idp
```ts
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:
1. Check the [issues](https://github.com/alaanpay/s2s-auth/issues) page.
2. Provide error messages, stack traces, and usage details.
3. Include your Node.js and library version.
## License
MIT