Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Backend authentication RBAC refactor #497

Open
wants to merge 52 commits into
base: v2/auth
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
cbf2603
feat(server/trpc): start rbac refactor
arthur-rl Jan 9, 2024
d5605c9
add(server/trpc): getSiteData to new folder structure
arthur-rl Jan 9, 2024
6a2026e
feat(server/trpc): updatePage to new rbac authentication
arthur-rl Jan 9, 2024
5a2de07
feat(server/trpc): updateSite to new rbac authentiction
arthur-rl Jan 9, 2024
89adfda
feat(trpc/context): userHasScope function
arthur-rl Jan 9, 2024
a401d98
refactor(trpc/routes): change gameplay routes over to new file struct…
arthur-rl Jan 13, 2024
fd3cd60
tweak(packages/identity): update session type and requested scope
arthur-rl Jan 13, 2024
77ea3f9
Merge branch 'v2/backend/rbac' of https://github.com/waldo-vision/wal…
arthur-rl Jan 13, 2024
b57435e
fix(env error): put env vars in turbo
ceriddenn Jan 13, 2024
c642f2b
refactor(files): save files with LF format
ceriddenn Jan 13, 2024
a26f29c
refactor(schema/migrations): rmvd mg dir & rmvd role field on user model
ceriddenn Jan 16, 2024
dc89bd9
chore(server): fix some major sec issues & finish file structure over…
ceriddenn Jan 16, 2024
3447cc6
refactor(schema): renamed a vote model and changed infrac type
ceriddenn Jan 16, 2024
779ba0f
feat(scopes): manage scopes within identity pkg instead of manually w…
ceriddenn Jan 16, 2024
7b8467d
fix(scopes): fixed some export issues
ceriddenn Jan 16, 2024
9b7d007
fix(vars,),feat(mapi): fixed env var, started machine-to-machine api
ceriddenn Jan 17, 2024
72ee3e0
feat(mapi): add logto roles to server session
ceriddenn Jan 17, 2024
f10d790
fix(mapi): remove hard coded uri
ceriddenn Jan 17, 2024
f47b7fb
chore(gp router): add try/catch block
ceriddenn Jan 18, 2024
74a2563
chore(routers): add try/catch blocks, fix returns and some other stuff
ceriddenn Jan 18, 2024
471f99b
feat(mapi/badges): start work on v2 fr's
ceriddenn Jan 19, 2024
c67a1d3
fix(mapi): remove testing code from endpoint
ceriddenn Jan 19, 2024
f665856
feat(next14): move trpc and everything over to next14, server comps
ceriddenn Jan 21, 2024
695583b
fix(env): remove hard coded env var
ceriddenn Jan 21, 2024
bfed1e3
refactor(next.config): add back prev diff
ceriddenn Jan 21, 2024
e585fec
refactor: clean a few things up
ceriddenn Mar 16, 2024
33f7721
refactor: move old comps into dep folder
ceriddenn Mar 16, 2024
642af3e
feats(v2): add platform home page, header & sidebar
ceriddenn Mar 16, 2024
e2497cb
feat(v2): add session context
ceriddenn Mar 16, 2024
78022a3
feat(v2): populate dash with session data & fix session data bug
ceriddenn Mar 16, 2024
92cdb2b
fix(header / page): add redirects to button hrefs
ceriddenn Mar 18, 2024
86c82e1
refactor/feat(dash): add loading comp, update session init stuff
ceriddenn Mar 20, 2024
22f8456
feat(session): add id field from waldo model, some other sessin stuff
ceriddenn Mar 20, 2024
f81ca32
feat(auth api): prepare for novu integration, refactor & comment rout…
ceriddenn Mar 20, 2024
7e8f5a5
refactor(session): add comments & refactor a few things
ceriddenn Mar 20, 2024
4efb046
feat(session): add scopes field to session obj
ceriddenn Mar 20, 2024
3a2e8ed
refactor(session): updating naming in createSession method
ceriddenn Mar 20, 2024
a7b919c
feat(novu): novu integration done (WIP)
ceriddenn Mar 21, 2024
5d8fcab
fix(novu): a bunch of bugs & errors fixed
ceriddenn Mar 21, 2024
88bb20e
feat(sidebar): add collapsible menu, start on submission pages
ceriddenn Mar 22, 2024
9c24871
refactor(sidebar): remove unused imports
ceriddenn Mar 22, 2024
d9066dc
refactor(header): remove console.logs
ceriddenn Mar 22, 2024
08f5fb8
feat(dash): start work on dash page content
ceriddenn Mar 23, 2024
39c4756
feat(sidebar): update submission nav options
ceriddenn Mar 23, 2024
d1c94fc
feat(sidebars, bugs): finished sidebars, worked on responsive layout
ceriddenn Mar 24, 2024
a17cbe5
fix(layout): add ! to conditional
ceriddenn Mar 24, 2024
d688649
fix(keys): add key prop to some elements
ceriddenn Mar 24, 2024
047edaf
fix(breakpoints): fix mobile breakpoints
ceriddenn Mar 24, 2024
bf14edb
fix(session reqs): fix constant api req
ceriddenn Mar 24, 2024
1f461a9
fix(mobile sidebar): remove fixed height
ceriddenn Mar 24, 2024
7d8641b
fix(sidebar): loading href check fixed
ceriddenn Mar 24, 2024
f019fe4
feat(upload): upload page logic wip
ceriddenn Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"development"
],
"hints": {
"axe/forms": [
"default",
{
"label": "off"
}
]
}
}
20 changes: 18 additions & 2 deletions apps/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ NEXT_PUBLIC_BASE_URL="" #// E.g. http://localhost:3000
COOKIESECRET='complex_password_at_least_32_characters_long'

# logto authorization / security

NEXT_PUBLIC_ID_RESOURCE_AUDIENCE="https://api.foo.bar/api"
NEXT_PUBLIC_ID_ISSUER=""
NEXT_PUBLIC_RESOURCE_AUDIENCE="https://api.foo.bar/api"
NEXT_PUBLIC_JWKS_ENDPOINT=https://localhost:3001/oidc/jwks

# Local Dev Stuff
Expand All @@ -24,3 +24,19 @@ NODE_TLS_REJECT_UNAUTHORIZED=0

# disable authentication verification (ONLY USE FOR TESTING PURPOSES)
#DISABLE_VERIFY_AUTH=0

APP_ID=""
APP_SECRET=""
ENDPOINT=""
BASE_URL=""
COOKIE_SECRET=""

MAPI_APP_ID=""
MAPI_APP_SECRET=""
MAPI_TOKEN_ENDPOINT=""
MAPI_RESOURCE_URI="https://default.logto.app/api"

NOVU_API_KEY=""
NOVU_BACKEND_URL=""
NOVU_WS_URL=""
NEXT_PUBLIC_NOVU_APP_ID=""
12 changes: 12 additions & 0 deletions apps/app/additional.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ declare namespace NodeJS {
DATABASE_URL: string;
APP_ID: string;
APP_SECRET: string;
ENDPOINT: string;
BASE_URL: string;
NEXT_PUBLIC_BASE_URL: string;
COOKIE_SECRET: string;
MAPI_APP_ID: string;
MAPI_APP_SECRET: string;
MAPI_TOKEN_ENDPOINT: string;
MAPI_RESOURCE_URI: string;
NODE_ENV: string;
NEXT_PUBLIC_BASE_URL: string;
NEXT_PUBLIC_JWKS_ENDPOINT: string;
NEXT_PUBLIC_RESOURCE_AUDIENCE: string;
NEXT_PUBLIC_ID_ISSUER: string;
NOVU_API_KEY: string;
NEXT_PUBLIC_NOVU_BACKEND_URL: string;
NEXT_PUBLIC_NOVU_WS_URL: string;
NEXT_PUBLIC_NOVU_APP_ID: string;
}
}
83 changes: 83 additions & 0 deletions apps/app/app/_styles/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 47.4% 11.2%;

--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;

--popover: 0 0% 100%;
--popover-foreground: 222.2 47.4% 11.2%;

--card: 0 0% 100%;
--card-foreground: 222.2 47.4% 11.2%;

--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;

--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;

--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;

--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;

--destructive: 0 100% 50%;
--destructive-foreground: 210 40% 98%;

--ring: 215 20.2% 65.1%;

--radius: 0.5rem;
}

.dark {
--background: 224 71% 4%;
--foreground: 213 31% 91%;

--muted: 223 47% 11%;
--muted-foreground: 215.4 16.3% 56.9%;

--popover: 224 71% 4%;
--popover-foreground: 215 20.2% 65.1%;

--card: 224 71% 4%;
--card-foreground: 213 31% 91%;

--border: 216 34% 17%;
--input: 216 34% 17%;

--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 1.2%;

--secondary: 222.2 47.4% 11.2%;
--secondary-foreground: 210 40% 98%;

--accent: 216 34% 17%;
--accent-foreground: 210 40% 98%;

--destructive: 0 63% 31%;
--destructive-foreground: 210 40% 98%;

--ring: 216 34% 17%;

--radius: 0.5rem;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
font-feature-settings: 'rlig' 1, 'calt' 1;
}
}
31 changes: 31 additions & 0 deletions apps/app/app/_styles/novu.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
body {
font-family: poppins;
-webkit-font-smoothing: auto;
-moz-font-smoothing: auto;
-moz-osx-font-smoothing: grayscale;
font-smoothing: auto;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: always;
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
background-color: grey;
}

h1 {
font-size: 1.5rem;
font-weight: bold;
margin-bottom: 1rem;
}
h2 {
font-size: 1.2rem;
font-weight: normal;
margin-bottom: 1rem;
}
h3 {
font-size: 1rem;
font-weight: normal;
}

body {
background-color: black;
}
33 changes: 17 additions & 16 deletions apps/app/utils/trpc.ts → apps/app/app/_trpc/client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { httpBatchLink, loggerLink } from '@trpc/client';
import { createTRPCNext } from '@trpc/next';
import { type inferRouterInputs, type inferRouterOutputs } from '@trpc/server';
import superjson from 'superjson';

import { type AppRouter } from '../server/trpc/router/_app';
import { getBaseUrl } from './baseurl';
import {
experimental_createActionHook,
experimental_createTRPCNextAppDirClient,
experimental_serverActionLink,
} from '@trpc/next/app-dir/client';
import { experimental_nextHttpLink } from '@trpc/next/app-dir/links/nextHttp';
import { type AppRouter } from '@server/trpc/router/_app';
import axios from 'axios';
import { cookies } from 'next/headers';

// this function receieves the user's access token from the nextjs api route
const retrieveAccessToken = async () => {
const req = await axios.get(
process.env.NEXT_PUBLIC_BASE_URL + '/api/logto/accesstoken',
{
withCredentials: true,
headers: {
Cookie: cookies().toString(),
},
},
);
const res = await req.data;
Expand All @@ -24,31 +29,27 @@ const retrieveAccessToken = async () => {
/**
* Trpc client for the frontend
*/
export const trpc = createTRPCNext<AppRouter>({
config({ ctx }) {
export const trpc = experimental_createTRPCNextAppDirClient<AppRouter>({
config() {
return {
transformer: superjson,
links: [
loggerLink({
enabled: opts =>
process.env.NODE_ENV === 'development' ||
(opts.direction === 'down' && opts.result instanceof Error),
}),
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
experimental_nextHttpLink({
batch: false,
url: `${process.env.NEXT_PUBLIC_BASE_URL}/api/trpc`,
headers: async () => {
return {
Authorization:
(await retrieveAccessToken()) == undefined
? undefined
: `Bearer ${await retrieveAccessToken()}`,
cookie: cookies().toString(),
};
},
}),
],
};
},
ssr: false,
});

/**
Expand Down
45 changes: 45 additions & 0 deletions apps/app/app/_trpc/serverClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { experimental_nextHttpLink } from '@trpc/next/app-dir/links/nextHttp';
import { experimental_createTRPCNextAppDirServer } from '@trpc/next/app-dir/server';
import type { AppRouter } from '@server/trpc/router/_app';
import { cookies } from 'next/headers';
import superjson from 'superjson';
import axios from 'axios';
const retrieveAccessToken = async () => {
const req = await axios.get(
process.env.NEXT_PUBLIC_BASE_URL + '/api/logto/accesstoken',
{
withCredentials: true,
headers: {
Cookie: cookies().toString(),
},
},
);
const res = await req.data;
if (!res.accessToken) return undefined;
return res.accessToken;
// gets returned and piped into TRPC headers
};

export const api = experimental_createTRPCNextAppDirServer<AppRouter>({
config() {
return {
transformer: superjson,
links: [
experimental_nextHttpLink({
revalidate: false,
batch: true,
url: `${process.env.NEXT_PUBLIC_BASE_URL}/api/trpc`,
headers: async () => {

return {
Authorization: `Bearer ${await retrieveAccessToken()}`,
cookie: cookies().toString(),
};
},
}),
],
};
},
});

// export const createAction =
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions apps/app/app/api/logto/accesstoken/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { logtoClient } from 'identity';
import { NextRequest } from 'next/server';

export async function GET(request: NextRequest) {
return logtoClient.handleUser({
fetchUserInfo: true,
getAccessToken: true,
resource: process.env.NEXT_PUBLIC_RESOURCE_AUDIENCE,
})(request);
}
Loading
Loading