-
Notifications
You must be signed in to change notification settings - Fork 0
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
New Feature - Authentication Middleware Injection #123
base: main
Are you sure you want to change the base?
Changes from 9 commits
e9e538d
0ecb6dc
e72b37b
bd711c7
937668e
96ca247
6032875
35b6fc6
ab8debb
665e5df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ LOG_LEVEL= | |
PORT=3030 | ||
UPLOAD_LIMIT='' | ||
PLURALIZE_SCHEMAS_ENABLED= | ||
ALLOWED_ORIGINS= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Request } from 'express'; | ||
|
||
import { type UserSessionResult } from '@overture-stack/lyric'; | ||
|
||
/** | ||
* Function to implement authentication logic. | ||
* This function is called by the authMiddleware to verify the user's authentication. | ||
* It returns the authentication result, which includes the authentication status and user information. | ||
* | ||
* @param req - Express request object | ||
* @returns User session result | ||
*/ | ||
export const authHandler = (_req: Request) => { | ||
// Guest User Session | ||
const authResult: UserSessionResult = { | ||
user: { username: 'Guest' }, | ||
}; | ||
|
||
return authResult; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
import helmet from 'helmet'; | ||
import { serve, setup } from 'swagger-ui-express'; | ||
|
||
import { errorHandler, provider } from '@overture-stack/lyric'; | ||
|
||
import { defaultAppConfig, getServerConfig } from './config/server.js'; | ||
import { appConfig, getServerConfig } from './config/app.js'; | ||
import swaggerDoc from './config/swagger.js'; | ||
import healthRouter from './routes/health.js'; | ||
import pingRouter from './routes/ping.js'; | ||
|
||
const serverConfig = getServerConfig(); | ||
const { allowedOrigins, port } = getServerConfig(); | ||
|
||
const lyricProvider = provider(defaultAppConfig); | ||
const lyricProvider = provider(appConfig); | ||
|
||
// Create Express server | ||
const app = express(); | ||
|
||
app.use(helmet()); | ||
|
||
app.use( | ||
cors({ | ||
origin: function (origin, callback) { | ||
if (!origin) { | ||
// allow requests with no origin | ||
// (like mobile apps or curl requests) | ||
return callback(null, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to add a feature flag (env var config) to enable this, and have it disabled by default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for noticing this. In regards to security this should be disabled by default. |
||
} else if (allowedOrigins && allowedOrigins.split(',').indexOf(origin) !== -1) { | ||
return callback(null, true); | ||
} | ||
const msg = 'The CORS policy for this site does not allow access from the specified Origin.'; | ||
return callback(new Error(msg), false); | ||
}, | ||
}), | ||
); | ||
|
||
// Ping Route | ||
app.use('/ping', pingRouter); | ||
|
||
|
@@ -35,6 +52,6 @@ app.use('/health', healthRouter); | |
|
||
app.use(errorHandler); | ||
// running the server | ||
app.listen(serverConfig.port, () => { | ||
console.log(`Starting Express server on http://localhost:${serverConfig.port}`); | ||
app.listen(port, () => { | ||
console.log(`Starting ExpressJS server on port ${port}`); | ||
}); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating Docs. Adding section to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those examples are really helpful! wonder if it would be more useful for integrators to have those as actual files instead (like a ready to copy and customize scaffolding) thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think providing our database migration script allows integrators to ensure Lyric will keep track of codebase and database schema in sync. For example, integrators over time can jump to latest version of Lyric, and they will be sure the database schema will be updated as well. In essence, how Lyric stores data shouldn't be a headache for implementers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the implementation of an auth handler used to provider Guest access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the whole project context, so I'm wondering why the readme example for authHandler contains actual auth logic, but the actual
authHandler
implementation just returns a hardcoded valueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the answer is related to this? #123 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handler implemented in this
apps/server
package is a basic implementation for demonstration, however, the details how to customize it is described in readme file