auth fix
This commit is contained in:
parent
b27fee6ece
commit
744020fc5f
@ -305,22 +305,22 @@ export class AuthService {
|
|||||||
// throw new BadRequestException("Invalid username or password")
|
// throw new BadRequestException("Invalid username or password")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (access_token && refresh_token && userSession.length > 0) {
|
// if (access_token && refresh_token && userSession.length > 0) {
|
||||||
|
|
||||||
const getSub: any = jwt.decode(refresh_token, { complete: true })
|
// const getSub: any = jwt.decode(refresh_token, { complete: true })
|
||||||
|
|
||||||
const user: any = await this.getUserDetailsById(getSub?.payload.sub)
|
// const user: any = await this.getUserDetailsById(getSub?.payload.sub)
|
||||||
|
|
||||||
if (user.email !== username) {
|
// if (user.email !== username) {
|
||||||
throw new UnauthorizedException("Authentication failed")
|
// throw new UnauthorizedException("Authentication failed")
|
||||||
}
|
// }
|
||||||
|
|
||||||
let tokens = await this.getTokenFromRefreshToken(req);
|
// let tokens = await this.getTokenFromRefreshToken(req);
|
||||||
const decoded = jwt.decode(access_token, { complete: true });
|
// const decoded = jwt.decode(access_token, { complete: true });
|
||||||
const email: any = (decoded && typeof decoded === 'object') ? (decoded as any).payload?.email : undefined;
|
// const email: any = (decoded && typeof decoded === 'object') ? (decoded as any).payload?.email : undefined;
|
||||||
return { ...tokens, email, ApplicationName: ROLE }
|
// return { ...tokens, email, ApplicationName: ROLE }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
const response = await axios.post(this.TOKEN_URL, params, {
|
const response = await axios.post(this.TOKEN_URL, params, {
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export class RolesGuard implements CanActivate {
|
|||||||
try {
|
try {
|
||||||
const decoded: any = jwt.decode(token);
|
const decoded: any = jwt.decode(token);
|
||||||
|
|
||||||
const roles: string[] = decoded?.resource_access?.['carnet-app']?.roles || [];
|
const roles: string[] = decoded?.resource_access?.[process.env.CLIENT_ID || '']?.roles || [];
|
||||||
const hasRole = requiredRoles.some(role => roles.includes(role));
|
const hasRole = requiredRoles.some(role => roles.includes(role));
|
||||||
|
|
||||||
if (!hasRole) {
|
if (!hasRole) {
|
||||||
|
|||||||
@ -20,7 +20,12 @@ async function bootstrap() {
|
|||||||
'http://localhost:5173',
|
'http://localhost:5173',
|
||||||
'https://policy.alphaomegainfosys.com',
|
'https://policy.alphaomegainfosys.com',
|
||||||
'https://sp.alphaomegainfosys.com',
|
'https://sp.alphaomegainfosys.com',
|
||||||
'https://client.alphaomegainfosys.com'
|
'https://policy-2.alphaomegainfosys.com',
|
||||||
|
'https://client-2.alphaomegainfosys.com',
|
||||||
|
'https://sp-2.alphaomegainfosys.com',
|
||||||
|
'https://policy-1.alphaomegainfosys.com',
|
||||||
|
'https://client-1.alphaomegainfosys.com',
|
||||||
|
'https://sp-1.alphaomegainfosys.com',
|
||||||
],
|
],
|
||||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||||
preflightContinue: false,
|
preflightContinue: false,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { RolesGuard } from 'src/guards/roles.guard';
|
|||||||
|
|
||||||
@ApiTags('Manage Clients - PG')
|
@ApiTags('Manage Clients - PG')
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles('psa')
|
@Roles('pca', 'psa', 'pua')
|
||||||
@Controller('2')
|
@Controller('2')
|
||||||
export class ManageClientsController {
|
export class ManageClientsController {
|
||||||
constructor(private readonly manageClientsService: ManageClientsService) { }
|
constructor(private readonly manageClientsService: ManageClientsService) { }
|
||||||
@ -24,19 +24,19 @@ export class ManageClientsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('UpdateClientContacts')
|
@Put('UpdateClientContacts')
|
||||||
@Roles('pca', 'psa')
|
// @Roles('pca', 'psa')
|
||||||
UpdateClientContacts(@Body() body: UpdateClientContactsDTO) {
|
UpdateClientContacts(@Body() body: UpdateClientContactsDTO) {
|
||||||
return this.manageClientsService.UpdateClientContacts(body);
|
return this.manageClientsService.UpdateClientContacts(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('UpdateClientLocations')
|
@Put('UpdateClientLocations')
|
||||||
@Roles('pca', 'psa')
|
// @Roles('pca', 'psa')
|
||||||
UpdateClientLocations(@Body() body: UpdateClientLocationsDTO) {
|
UpdateClientLocations(@Body() body: UpdateClientLocationsDTO) {
|
||||||
return this.manageClientsService.UpdateClientLocations(body);
|
return this.manageClientsService.UpdateClientLocations(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('CreateClientContacts')
|
@Post('CreateClientContacts')
|
||||||
@Roles('pca', 'psa')
|
// @Roles('pca', 'psa')
|
||||||
CreateClientContact(@Body() body: CreateClientContactsDTO) {
|
CreateClientContact(@Body() body: CreateClientContactsDTO) {
|
||||||
return this.manageClientsService.CreateClientContact(body);
|
return this.manageClientsService.CreateClientContact(body);
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ export class ManageClientsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('CreateClientLocations')
|
@Post('CreateClientLocations')
|
||||||
@Roles('pca', 'psa')
|
// @Roles('pca', 'psa', 'pua')
|
||||||
CreateClientLocation(@Body() body: CreateClientLocationsDTO) {
|
CreateClientLocation(@Body() body: CreateClientLocationsDTO) {
|
||||||
return this.manageClientsService.CreateClientLocation(body);
|
return this.manageClientsService.CreateClientLocation(body);
|
||||||
}
|
}
|
||||||
@ -73,19 +73,19 @@ export class ManageClientsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('GetPreparerContactsByClientid/:P_SPID/:P_CLIENTID')
|
@Get('GetPreparerContactsByClientid/:P_SPID/:P_CLIENTID')
|
||||||
@Roles('pca', 'psa')
|
// @Roles('pca', 'psa')
|
||||||
GetPreparerContactsByClientid(@Param() body: GetClientDTO) {
|
GetPreparerContactsByClientid(@Param() body: GetClientDTO) {
|
||||||
return this.manageClientsService.GetPreparerContactsByClientid(body);
|
return this.manageClientsService.GetPreparerContactsByClientid(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('GetPreparerContactsbyClientLocationID/:P_SPID/:P_LOCATIONID')
|
@Get('GetPreparerContactsbyClientLocationID/:P_SPID/:P_LOCATIONID')
|
||||||
@Roles('pca', 'psa')
|
// @Roles('pca', 'psa')
|
||||||
GetPreparerContactsbyClientLocationID(@Param() body: GetClientContactByLacationIdDTO) {
|
GetPreparerContactsbyClientLocationID(@Param() body: GetClientContactByLacationIdDTO) {
|
||||||
return this.manageClientsService.GetPreparerContactsbyClientLocationID(body);
|
return this.manageClientsService.GetPreparerContactsbyClientLocationID(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('GetPreparerLocByClientid/:P_SPID/:P_CLIENTID')
|
@Get('GetPreparerLocByClientid/:P_SPID/:P_CLIENTID')
|
||||||
@Roles('pca', 'psa')
|
// @Roles('pca', 'psa')
|
||||||
GetPreparerLocByClientid(@Param() body: GetClientDTO) {
|
GetPreparerLocByClientid(@Param() body: GetClientDTO) {
|
||||||
return this.manageClientsService.GetPreparerLocByClientid(body);
|
return this.manageClientsService.GetPreparerLocByClientid(body);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -436,7 +436,7 @@ export class ManageClientsService {
|
|||||||
const pgArrayLiteral = `{${addressLiterals.join(',')}}`;
|
const pgArrayLiteral = `{${addressLiterals.join(',')}}`;
|
||||||
|
|
||||||
const callProcQuery = `
|
const callProcQuery = `
|
||||||
CALL "CARNETSYS".managepreparer_pkg_updateclientlocations($1, $2, $3::"CARNETSYS".addresstable[], $4, $5)
|
CALL "CARNETSYS".managepreparer_pkg_createclientlocation($1, $2, $3::"CARNETSYS".addresstable[], $4, $5)
|
||||||
`;
|
`;
|
||||||
await client.query(callProcQuery,
|
await client.query(callProcQuery,
|
||||||
[
|
[
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user