Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
modscleo4 committed Feb 20, 2024
1 parent e065255 commit 647f33e
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 133 deletions.
90 changes: 45 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/app/handler/AuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AuthServiceProvider, JWTServiceProvider } from "midori/providers";
import { Payload } from "midori/util/jwt.js";
import { generateUUID } from "midori/util/uuid.js";

import UserDAO from "@core/dao/UserDAO.js";
import { prisma } from "@core/lib/Prisma.js";

import { OpenIDServiceProvider } from "@app/providers/OpenIDServiceProvider.js";
import OpenIDService from "@app/services/OpenIDService.js";
Expand Down Expand Up @@ -95,11 +95,13 @@ export class Callback extends Handler {

const OauthUser = await identity_response.json();

const user = await UserDAO.create({
id: generateUUID(),
username: OauthUser.preferred_username,
password: null,
email: OauthUser.email,
const user = await prisma.user.create({
data: {
id: generateUUID(),
username: OauthUser.preferred_username,
password: null,
email: OauthUser.email,
}
});

const issuedAt = Date.now();
Expand Down
9 changes: 6 additions & 3 deletions src/app/middleware/OauthScopeMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

import { HTTPError } from "midori/errors";
import { EStatusCode, Middleware, Request, Response } from "midori/http";
import { AuthBearerMiddleware } from "midori/middlewares";
import { Payload } from "midori/util/jwt.js";
import { Constructor } from "midori/util/types.js";

export default function OauthScopeMiddlewareFactory(options: { scopes: string[]; }): Constructor<Middleware> {
return class extends Middleware {
async process(req: Request, next: (req: Request) => Promise<Response>): Promise<Response> {
if (req.container.get('::jwt')) {
const userScopes = (req.container.get('::jwt').scope ?? '').split(' ');
override async process(req: Request, next: (req: Request) => Promise<Response>): Promise<Response> {
const jwt = req.container.get(AuthBearerMiddleware.TokenKey) as (Payload & { username: string; scope: string; }) | undefined;
if (jwt) {
const userScopes = (jwt.scope ?? '').split(' ');
for (const scope of options.scopes) {
if (!userScopes.includes(scope)) {
throw new HTTPError(`Insufficient permissions: ${scope}`, EStatusCode.FORBIDDEN);
Expand Down
2 changes: 1 addition & 1 deletion src/app/providers/GamesServiceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ServiceProvider, Application } from 'midori/app';
import GamesService from '@app/services/GamesService.js';

export default class GamesServiceProvider extends ServiceProvider<GamesService> {
static service: string = 'ChessGames';
static override service: symbol = Symbol('ChessGames');

register(app: Application): GamesService {
return new GamesService();
Expand Down
2 changes: 1 addition & 1 deletion src/app/providers/OpenIDServiceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Constructor } from "midori/util/types.js";
import OpenIDService from "@app/services/OpenIDService.js";

export abstract class OpenIDServiceProvider extends ServiceProvider<OpenIDService> {
static service: string = 'OpenID';
static override service: symbol = Symbol('OpenID');
}

export default function (openIDService: OpenIDService): Constructor<OpenIDServiceProvider> & { [K in keyof typeof OpenIDServiceProvider]: typeof OpenIDServiceProvider[K] } {
Expand Down
7 changes: 3 additions & 4 deletions src/app/services/PrismaUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import { prisma } from "@core/lib/Prisma.js";
import { User, UserService } from "midori/auth";
import { Hash } from "midori/hash";

import UserDAO from "@core/dao/UserDAO.js";

export default class PrismaUserService extends UserService {
#hash: Hash;

Expand All @@ -29,11 +28,11 @@ export default class PrismaUserService extends UserService {
}

async getUserById(id: string): Promise<User | null> {
return await UserDAO.get({ select: { id: true, username: true }, where: { id } });
return await prisma.user.findFirst({ select: { id: true, username: true }, where: { id } });
}

async getUserByCredentials(username: string, password: string): Promise<User | null> {
const user = await UserDAO.get({ select: { id: true, username: true, password: true }, where: { username } });
const user = await prisma.user.findFirst({ select: { id: true, username: true, password: true }, where: { username } });

if (!user || !user.password) {
return null;
Expand Down
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default function config(server: Server): void {
enc: process.env.JWE_ENCRYPTION || 'A256GCM',
secret: process.env.JWE_SECRET,
privateKeyFile: process.env.JWE_PRIVATE_KEY,
ephemeralPrivateKeyFile: process.env.JWE_EPHEMERAL_KEY,
},
}));

Expand Down
51 changes: 0 additions & 51 deletions src/core/dao/UserDAO.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/core/entity/User.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import OpenIDService from "@app/services/OpenIDService.js";

export default function providers(server: Server): void {
server.install(RouterServiceProviderFactory(router));
server.install(LoggerServiceProviderFactory(new ConsoleLogger({ colorsEnabled: true, minLevel: LogLevel.DEBUG })));
server.install(LoggerServiceProviderFactory(new ConsoleLogger({ formattingEnabled: true, minLevel: LogLevel.DEBUG })));

// Add providers here
// Recover the provider with app.services.get(ServiceProvider) in your handlers and middleware constructors
Expand Down
4 changes: 1 addition & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ config(server);
providers(server);
pipeline(server);
cron(server);
ws(server);

const port = parseInt(process.env.PORT || '3000');

await new Promise<void>((resolve, reject) => {
server.listen(port).on('listening', async () => {
console.log(`Server is running on port ${port}`);

console.log(`Server is running on port ${port} in ${server.production ? 'production' : 'development'} mode`);
await prisma.$connect();
resolve();
}).on('close', async () => {
Expand Down
Loading

0 comments on commit 647f33e

Please sign in to comment.