switching to auth0
This commit is contained in:
@@ -32,17 +32,17 @@ import { join } from 'path';
|
|||||||
}),
|
}),
|
||||||
HealthModule,
|
HealthModule,
|
||||||
LogModule,
|
LogModule,
|
||||||
MsGraphModule.registerAsync({
|
// MsGraphModule.registerAsync({
|
||||||
inject: [ConfigService],
|
// inject: [ConfigService],
|
||||||
imports: [ConfigModule],
|
// imports: [ConfigModule],
|
||||||
useFactory: async (configService: ConfigService) => {
|
// useFactory: async (configService: ConfigService) => {
|
||||||
return {
|
// return {
|
||||||
clientId: configService.get<string>('clientId'),
|
// clientId: configService.get<string>('clientId'),
|
||||||
clientSecret: configService.get<string>('clientSecret'),
|
// clientSecret: configService.get<string>('clientSecret'),
|
||||||
tenantId: configService.get<string>('tenantId')
|
// tenantId: configService.get<string>('tenantId')
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}),
|
// }),
|
||||||
PilotModule,
|
PilotModule,
|
||||||
ServeStaticModule.forRoot({
|
ServeStaticModule.forRoot({
|
||||||
rootPath: join(__dirname, '../..', 'client', 'dist')
|
rootPath: join(__dirname, '../..', 'client', 'dist')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { JwtPayload } from "jwt-decode";
|
import { JwtPayload } from "jwt-decode";
|
||||||
|
|
||||||
export interface CustomJwtPayload extends JwtPayload {
|
export interface CustomJwtPayload extends JwtPayload {
|
||||||
roles: string[];
|
permissions: string[];
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@ import { CallHandler, ExecutionContext, NestInterceptor, UnauthorizedException }
|
|||||||
import { Observable, map } from 'rxjs';
|
import { Observable, map } from 'rxjs';
|
||||||
import { LogEntity } from './log.entity';
|
import { LogEntity } from './log.entity';
|
||||||
import { jwtDecode } from 'jwt-decode';
|
import { jwtDecode } from 'jwt-decode';
|
||||||
import { CustomJwtPayload } from 'src/interfaces/customJwtPayload.interface';
|
|
||||||
import { IS_PUBLIC_KEY } from '@noahspan/noahspan-modules';
|
import { IS_PUBLIC_KEY } from '@noahspan/noahspan-modules';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
|
|
||||||
@@ -38,9 +37,10 @@ export class LogInterceptor implements NestInterceptor {
|
|||||||
if (req.headers.authorization) {
|
if (req.headers.authorization) {
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
const token = authHeader && authHeader.split(' ')[1];
|
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);
|
const logs = limitData(data);
|
||||||
|
|
||||||
return logs;
|
return logs;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
||||||
import { jwtDecode } from 'jwt-decode';
|
import { jwtDecode } from 'jwt-decode';
|
||||||
import { Observable, map } from 'rxjs';
|
import { Observable, map } from 'rxjs';
|
||||||
import { CustomJwtPayload } from 'src/interfaces/customJwtPayload.interface';
|
|
||||||
import { PilotEntity } from './pilot.entity';
|
import { PilotEntity } from './pilot.entity';
|
||||||
import { IS_PUBLIC_KEY } from '@noahspan/noahspan-modules';
|
import { IS_PUBLIC_KEY } from '@noahspan/noahspan-modules';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
@@ -30,9 +29,10 @@ export class PilotInterceptor implements NestInterceptor {
|
|||||||
if (req.headers.authorization) {
|
if (req.headers.authorization) {
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
const token = authHeader && authHeader.split(' ')[1];
|
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)
|
const pilots = limitData(data)
|
||||||
|
|
||||||
return pilots;
|
return pilots;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
"@tailwindcss/vite": "^4.1.13",
|
"@tailwindcss/vite": "^4.1.13",
|
||||||
"@tanstack/react-table": "^8.21.3",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"daisyui": "^5.1.10",
|
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"framer-motion": "^12.23.24",
|
"framer-motion": "^12.23.24",
|
||||||
"leaflet": "^1.9.4",
|
"leaflet": "^1.9.4",
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { createReactOidc } from "oidc-spa/react";
|
import { createReactOidc } from "oidc-spa/react";
|
||||||
|
|
||||||
export const { OidcProvider, useOidc, getOidc } = createReactOidc(async () => ({
|
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,
|
clientId: import.meta.env.VITE_CLIENT_ID,
|
||||||
homeUrl: import.meta.env.VITE_BASE_URL,
|
homeUrl: import.meta.env.VITE_BASE_URL,
|
||||||
scopes: ['email', 'openid', 'profile', `api://${import.meta.env.VITE_CLIENT_ID}/user_impersonation`],
|
|
||||||
autoLogin: false,
|
autoLogin: false,
|
||||||
postLoginRedirectUrl: '/',
|
postLoginRedirectUrl: '/',
|
||||||
noIframe: true
|
noIframe: true,
|
||||||
|
extraQueryParams: {
|
||||||
|
audience: "api://flying-test-api"
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
@@ -8,7 +8,8 @@ export const useUserRole = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isUserLoggedIn && decodedIdToken) {
|
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;
|
let newUserRole: string | undefined;
|
||||||
|
|
||||||
|
|||||||
1
client/src/vite-env.d.ts
vendored
1
client/src/vite-env.d.ts
vendored
@@ -3,6 +3,7 @@
|
|||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
readonly VITE_BASE_URL: string;
|
readonly VITE_BASE_URL: string;
|
||||||
readonly VITE_CLIENT_ID: string;
|
readonly VITE_CLIENT_ID: string;
|
||||||
|
readonly VITE_ISSUER_URI: string;
|
||||||
readonly VITE_TENANT_ID: string;
|
readonly VITE_TENANT_ID: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -91,7 +91,6 @@
|
|||||||
"@tailwindcss/vite": "^4.1.13",
|
"@tailwindcss/vite": "^4.1.13",
|
||||||
"@tanstack/react-table": "^8.21.3",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"daisyui": "^5.1.10",
|
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"framer-motion": "^12.23.24",
|
"framer-motion": "^12.23.24",
|
||||||
"leaflet": "^1.9.4",
|
"leaflet": "^1.9.4",
|
||||||
@@ -230,6 +229,7 @@
|
|||||||
"version": "5.1.10",
|
"version": "5.1.10",
|
||||||
"resolved": "https://registry.npmjs.org/daisyui/-/daisyui-5.1.10.tgz",
|
"resolved": "https://registry.npmjs.org/daisyui/-/daisyui-5.1.10.tgz",
|
||||||
"integrity": "sha512-p1J/HME2WmaSiy6u2alIbeP3gd5PNVft3+6Bdll0BRSm/UdI4084+pD01LxFug/5wGexNewWqbcEL6nB2n2o+Q==",
|
"integrity": "sha512-p1J/HME2WmaSiy6u2alIbeP3gd5PNVft3+6Bdll0BRSm/UdI4084+pD01LxFug/5wGexNewWqbcEL6nB2n2o+Q==",
|
||||||
|
"peer": true,
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/saadeghi/daisyui?sponsor=1"
|
"url": "https://github.com/saadeghi/daisyui?sponsor=1"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user