mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: use the same Authorization header for jwt and api key
This commit is contained in:
@@ -13,8 +13,8 @@ export class ApiKeyStrategy extends PassportStrategy(
|
||||
) {
|
||||
super(
|
||||
{
|
||||
header: 'x-api-key',
|
||||
prefix: '',
|
||||
header: 'Authorization',
|
||||
prefix: 'Bearer ',
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { JwtAuthGuard } from '../guards/jwt.guard';
|
||||
import { ApiKeyAuthGuard } from './AuthApiKey.guard';
|
||||
import { getAuthApiKey } from '../Auth.utils';
|
||||
|
||||
// mixed-auth.guard.ts
|
||||
@Injectable()
|
||||
@@ -12,7 +13,7 @@ export class MixedAuthGuard implements CanActivate {
|
||||
|
||||
canActivate(context: ExecutionContext) {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const apiKey = request.headers['x-api-key'];
|
||||
const apiKey = getAuthApiKey(request.headers['authorization'] || '');
|
||||
|
||||
if (apiKey) {
|
||||
return this.apiKeyGuard.canActivate(context);
|
||||
|
||||
Reference in New Issue
Block a user