mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
117 fix oauth (#127)
* change session cookie from 'strict' to 'lax' to fix "forbidden" issue * add scope settings to Google some additional improvements: * update ESLint settings to allow unused parameters before used ones some related discussions: * https://github.com/auth0/passport-auth0/issues/70 * https://stackoverflow.com/questions/59221899/add-samesite-attribute-to-passport-js-session-cookie
This commit is contained in:
8 files changed
+16
-9
No files matched your search
+1
-1
@@ -51,7 +51,7 @@ module.exports = {
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
args: 'all',
|
||||
args: 'after-used',
|
||||
argsIgnorePattern: '^_',
|
||||
caughtErrors: 'all',
|
||||
caughtErrorsIgnorePattern: '^_',
|
||||
|
||||
@@ -26,7 +26,7 @@ const api = axios.create({
|
||||
async function readOrNone(file) {
|
||||
try {
|
||||
return await fs.readFile(file, 'utf8')
|
||||
} catch (err) {
|
||||
} catch (_) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ async function collectFilesInfo(inputPath, level = 0, hiddenFiles = false) {
|
||||
)
|
||||
)
|
||||
files.push(...result.flat())
|
||||
} catch (err) {
|
||||
} catch (_) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ async function discoverFiles(argv) {
|
||||
.map((p) => collectFilesInfo(p, 0, argv.a || argv.all))
|
||||
)
|
||||
return { discover: result.flat() }
|
||||
} catch (err) {
|
||||
} catch (_) {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,10 @@ router.get('/available-methods', (req, res) => {
|
||||
})
|
||||
|
||||
if (enabledMethods.google) {
|
||||
router.get('/google', passport.authenticate('google'))
|
||||
router.get(
|
||||
'/google',
|
||||
passport.authenticate('google', { scope: ['email', 'profile'] })
|
||||
)
|
||||
router.get(
|
||||
'/google/callback',
|
||||
authenticateRateLimit,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { User } from '@linux-odyssey/models'
|
||||
import type { Profile } from 'passport'
|
||||
import type { VerifyCallback } from 'passport-oauth2'
|
||||
import logger from '../utils/logger.js'
|
||||
|
||||
export default async function oauthVerify(
|
||||
provider: string,
|
||||
@@ -37,6 +38,7 @@ export default async function oauthVerify(
|
||||
email: user.email,
|
||||
})
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
return cb(
|
||||
err instanceof Error ? err : new Error('An unknown error occurred')
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import passport from 'passport'
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
import type { Express } from 'express'
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
import passwordStrategy from './passwordStrategy.js'
|
||||
import jwtStrategy from './jwtStrategy.js'
|
||||
import googleStrategy from './googleStrategy.js'
|
||||
@@ -30,7 +30,8 @@ passport.serializeUser((user: Express.User, done) => {
|
||||
process.nextTick(async () => {
|
||||
try {
|
||||
if (!('id' in user)) {
|
||||
done(new Error('User has no _id'))
|
||||
// OAuth new user
|
||||
done(null, user)
|
||||
return
|
||||
}
|
||||
const { id } = user
|
||||
@@ -39,6 +40,7 @@ passport.serializeUser((user: Express.User, done) => {
|
||||
}
|
||||
done(null, user)
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
done(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ export default function errorHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
next: NextFunction
|
||||
_next: NextFunction
|
||||
) {
|
||||
logger.error(err) // Log error stack trace to the console
|
||||
res.status(500).send({ message: 'Something broke!' }) // Send error response
|
||||
|
||||
@@ -12,7 +12,7 @@ export default session({
|
||||
domain: config.domain,
|
||||
httpOnly: true,
|
||||
secure: config.protocol === 'https:',
|
||||
sameSite: 'strict',
|
||||
sameSite: 'lax',
|
||||
maxAge: config.sessionMaxAge,
|
||||
},
|
||||
store: MongoStore.create({
|
||||
|
||||
Reference in new issue
Block a user