Compare commits

...

1 Commits

Author SHA1 Message Date
64c94ca9f4 switching to auth0 (#103) 2025-12-02 17:10:45 -06:00
9 changed files with 27 additions and 24 deletions

View File

@@ -32,17 +32,17 @@ import { join } from 'path';
}),
HealthModule,
LogModule,
MsGraphModule.registerAsync({
inject: [ConfigService],
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
return {
clientId: configService.get<string>('clientId'),
clientSecret: configService.get<string>('clientSecret'),
tenantId: configService.get<string>('tenantId')
}
}
}),
// MsGraphModule.registerAsync({
// inject: [ConfigService],
// imports: [ConfigModule],
// useFactory: async (configService: ConfigService) => {
// return {
// clientId: configService.get<string>('clientId'),
// clientSecret: configService.get<string>('clientSecret'),
// tenantId: configService.get<string>('tenantId')
// }
// }
// }),
PilotModule,
ServeStaticModule.forRoot({
rootPath: join(__dirname, '../..', 'client', 'dist')

View File

@@ -1,5 +1,5 @@
import { JwtPayload } from "jwt-decode";
export interface CustomJwtPayload extends JwtPayload {
roles: string[];
permissions: string[];
}

View File

@@ -2,7 +2,6 @@ import { CallHandler, ExecutionContext, NestInterceptor, UnauthorizedException }
import { Observable, map } from 'rxjs';
import { LogEntity } from './log.entity';
import { jwtDecode } from 'jwt-decode';
import { CustomJwtPayload } from 'src/interfaces/customJwtPayload.interface';
import { IS_PUBLIC_KEY } from '@noahspan/noahspan-modules';
import { Reflector } from '@nestjs/core';
@@ -38,9 +37,10 @@ export class LogInterceptor implements NestInterceptor {
if (req.headers.authorization) {
const authHeader = req.headers.authorization;
const token = authHeader && authHeader.split(' ')[1];
const jwtPayload: CustomJwtPayload = jwtDecode(token);
const jwtPayload = jwtDecode(token);
const rolesKeyName = Object.keys(jwtPayload).find((key) => key.includes('roles'));
if (jwtPayload.roles.includes('Flying.Read')) {
if (jwtPayload[rolesKeyName].includes('Flying.Read')) {
const logs = limitData(data);
return logs;

View File

@@ -1,7 +1,6 @@
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import { jwtDecode } from 'jwt-decode';
import { Observable, map } from 'rxjs';
import { CustomJwtPayload } from 'src/interfaces/customJwtPayload.interface';
import { PilotEntity } from './pilot.entity';
import { IS_PUBLIC_KEY } from '@noahspan/noahspan-modules';
import { Reflector } from '@nestjs/core';
@@ -30,9 +29,10 @@ export class PilotInterceptor implements NestInterceptor {
if (req.headers.authorization) {
const authHeader = req.headers.authorization;
const token = authHeader && authHeader.split(' ')[1];
const jwtPayload: CustomJwtPayload = jwtDecode(token);
const jwtPayload = jwtDecode(token);
const rolesKeyName = Object.keys(jwtPayload).find((key) => key.includes('roles'));
if (jwtPayload.roles.includes('Flying.Read')) {
if (jwtPayload[rolesKeyName].includes('Flying.Read')) {
const pilots = limitData(data)
return pilots;

View File

@@ -20,7 +20,6 @@
"@tailwindcss/vite": "^4.1.13",
"@tanstack/react-table": "^8.21.3",
"axios": "^1.7.2",
"daisyui": "^5.1.10",
"dotenv": "^16.4.7",
"framer-motion": "^12.23.24",
"leaflet": "^1.9.4",

View File

@@ -1,11 +1,13 @@
import { createReactOidc } from "oidc-spa/react";
export const { OidcProvider, useOidc, getOidc } = createReactOidc(async () => ({
issuerUri: `https://login.microsoftonline.com/${import.meta.env.VITE_TENANT_ID}/v2.0`,
issuerUri: import.meta.env.VITE_ISSUER_URI,
clientId: import.meta.env.VITE_CLIENT_ID,
homeUrl: import.meta.env.VITE_BASE_URL,
scopes: ['email', 'openid', 'profile', `api://${import.meta.env.VITE_CLIENT_ID}/user_impersonation`],
autoLogin: false,
postLoginRedirectUrl: '/',
noIframe: true
noIframe: true,
extraQueryParams: {
audience: "api://flying-test-api"
}
}));

View File

@@ -8,7 +8,8 @@ export const useUserRole = () => {
useEffect(() => {
if (isUserLoggedIn && decodedIdToken) {
const idTokenRoles: string[] = decodedIdToken!.roles as string[];
const rolesKeyName: string | undefined = Object.keys(decodedIdToken).find((key) => key.includes('roles'));
const idTokenRoles: string[] = decodedIdToken[rolesKeyName!] as string[];
let newUserRole: string | undefined;

View File

@@ -3,6 +3,7 @@
interface ImportMetaEnv {
readonly VITE_BASE_URL: string;
readonly VITE_CLIENT_ID: string;
readonly VITE_ISSUER_URI: string;
readonly VITE_TENANT_ID: string;
}

2
package-lock.json generated
View File

@@ -91,7 +91,6 @@
"@tailwindcss/vite": "^4.1.13",
"@tanstack/react-table": "^8.21.3",
"axios": "^1.7.2",
"daisyui": "^5.1.10",
"dotenv": "^16.4.7",
"framer-motion": "^12.23.24",
"leaflet": "^1.9.4",
@@ -230,6 +229,7 @@
"version": "5.1.10",
"resolved": "https://registry.npmjs.org/daisyui/-/daisyui-5.1.10.tgz",
"integrity": "sha512-p1J/HME2WmaSiy6u2alIbeP3gd5PNVft3+6Bdll0BRSm/UdI4084+pD01LxFug/5wGexNewWqbcEL6nB2n2o+Q==",
"peer": true,
"funding": {
"url": "https://github.com/saadeghi/daisyui?sponsor=1"
}