📝Middleware - Authorization
The middleware for check authorization.
Imports
import { AuthorizationMiddleware } from 'niro-health';
Environment Variables
name
description
MASTER_KEY
The master key used to authenticate the routes.
Write .env
file with environment variable. Below has an example:
MASTER_KEY=eJwFwcFOwzAMANBviZxTJB+c2Il7q7ZdKGWlbGzqKaKbWihTGYzR3+e9knQFqTI7dB5Hz1FCIacPZ8LdF9S4Ldrwa8wymrt7YcJ60xxlQU25g7+068McmjU6GKw3xMr5RI/gIzz3sorqiA3rTRvGs9JUu9bo6NCifRImwQLVwnhRzSml48OeQecSbPiZM+8OSHotaeFNjgXE6/snyVCj+Sa8nvELJnFyFoC07Muh7LQs4jZRf1vnSLZqJxdu/tLmrj+JrUzwYjmxKV4Rwecgb0gY0z8TjUCv
Method of Use
To use this middleware, you need to inject it into the desired module.
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import {
AuthorizationMiddleware,
ConfigurationService,
ValidatorRegexpService,
StringExService,
i18nService,
RedisService,
DebugService,
PropStringService,
AppHostService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
controllers: [AppController],
providers: [
AppService,
{
provide: 'IConfigurationService',
useClass: ConfigurationService,
},
{
provide: 'IValidatorRegexpService',
useClass: ValidatorRegexpService,
},
{
provide: 'IStringExService',
useClass: StringExService,
},
{
provide: 'Ii18nService',
useClass: i18nService,
},
{
provide: 'IRedisService',
useClass: RedisService,
},
{
provide: 'IDebugService',
useClass: DebugService,
},
{
provide: 'IPropStringService',
useClass: PropStringService,
},
{
provide: 'IAppHostService',
useClass: AppHostService,
},
],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(AuthorizationMiddleware)
.exclude('(.*)/private-keys/master-key')
.forRoutes('api');
}
}
With dependencies
You will need to inject the following interfaces.
Interface
Service
IConfigurationService
IValidatorRegexpService
IStringExService
Ii18nService
IRedisService
IDebugService
IPropStringService
IAppHostService
Methods
Method
Scope
Description
_invalidMasterKey
private
Check if the master key is invalid.
_invalidPrivateKey
private
Check if the private key is invalid.
use
public
The method for check authorization.
Last updated