mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-27 03:31:46 +00:00
modified serialization and deserialization of users to only use the useres id, only creating oidc related enpoints, if oidc is configured
This commit is contained in:
parent
cd3feee583
commit
4b93882494
2 changed files with 13 additions and 21 deletions
|
|
@ -2,6 +2,7 @@ const bcrypt = require('bcryptjs')
|
||||||
const jwt = require('jsonwebtoken')
|
const jwt = require('jsonwebtoken')
|
||||||
const Logger = require('./Logger')
|
const Logger = require('./Logger')
|
||||||
const User = require('./objects/User')
|
const User = require('./objects/User')
|
||||||
|
const { getId } = require('./utils/index')
|
||||||
|
|
||||||
class Auth {
|
class Auth {
|
||||||
constructor(db) {
|
constructor(db) {
|
||||||
|
|
@ -216,7 +217,6 @@ class Auth {
|
||||||
|
|
||||||
async handleOIDCVerification(issuer, profile, cb) {
|
async handleOIDCVerification(issuer, profile, cb) {
|
||||||
Logger.debug(`[Auth] handleOIDCVerification ${issuer}`)
|
Logger.debug(`[Auth] handleOIDCVerification ${issuer}`)
|
||||||
|
|
||||||
let user = this.db.users.find(u => u.id === profile.id)
|
let user = this.db.users.find(u => u.id === profile.id)
|
||||||
if (!user && this.db.SSOSettings.createNewUser) {
|
if (!user && this.db.SSOSettings.createNewUser) {
|
||||||
// create a user
|
// create a user
|
||||||
|
|
|
||||||
|
|
@ -140,16 +140,16 @@ class Server {
|
||||||
passportInit() {
|
passportInit() {
|
||||||
if (this.db.SSOSettings.isOIDCConfigured) {
|
if (this.db.SSOSettings.isOIDCConfigured) {
|
||||||
Logger.debug(`[Server] passportInit OIDC is configured - init`)
|
Logger.debug(`[Server] passportInit OIDC is configured - init`)
|
||||||
|
|
||||||
passport.serializeUser((user, next) => {
|
passport.serializeUser((user, next) => {
|
||||||
next(null, user);
|
next(null, {userId: user.id});
|
||||||
})
|
})
|
||||||
passport.deserializeUser((obj, next) => {
|
passport.deserializeUser((obj, next) => {
|
||||||
|
this.db.users.find(u => u.id === obj.userId)
|
||||||
next(null, obj);
|
next(null, obj);
|
||||||
})
|
})
|
||||||
|
|
||||||
// Initialize passport OIDC verification
|
// Initialize passport OIDC verification
|
||||||
passport.use(new OidcStrategy(this.db.SSOSettings.getOIDCSettings(), this.auth.handleOIDCVerification))
|
passport.use(new OidcStrategy(this.db.SSOSettings.getOIDCSettings(), this.auth.handleOIDCVerification.bind(this.auth)))
|
||||||
} else {
|
} else {
|
||||||
Logger.debug(`[Server] passportInit OIDC not configured`)
|
Logger.debug(`[Server] passportInit OIDC not configured`)
|
||||||
}
|
}
|
||||||
|
|
@ -260,23 +260,15 @@ class Server {
|
||||||
|
|
||||||
app.post('/logout', this.authMiddleware.bind(this), this.logout.bind(this))
|
app.post('/logout', this.authMiddleware.bind(this), this.logout.bind(this))
|
||||||
|
|
||||||
app.get("/oidc/login", (() => {
|
if (this.db.SSOSettings.isOIDCConfigured) {
|
||||||
if (!this.db.SSOSettings.isOIDCConfigured) return (req, res) => res.redirect("/");
|
app.get("/oidc/login", passport.authenticate('openidconnect'))
|
||||||
return passport.authenticate('openidconnect')
|
app.get("/oidc/callback", passport.authenticate('openidconnect', { failureRedirect: '/login', failureMessage: true }),
|
||||||
})())
|
async (req, res) => {
|
||||||
|
res.cookie('sso', true, { httpOnly: false /* TODO: Set secure: true */ });
|
||||||
app.get("/oidc/callback",
|
res.redirect('/');
|
||||||
(() => {
|
}
|
||||||
if (!this.db.SSOSettings.isOIDCConfigured) return (req, res) => res.redirect("/");
|
)
|
||||||
return passport.authenticate('openidconnect', { failureRedirect: '/oidc/login', failureMessage: true }),
|
}
|
||||||
async (req, res) => {
|
|
||||||
const token = this.auth.generateAccessToken({ userId: req.user.id })
|
|
||||||
res.cookie('sso', true, { httpOnly: false /* TODO: Set secure: true */ });
|
|
||||||
|
|
||||||
res.redirect('/');
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
)
|
|
||||||
|
|
||||||
app.get('/ping', (req, res) => {
|
app.get('/ping', (req, res) => {
|
||||||
Logger.info('Recieved ping')
|
Logger.info('Recieved ping')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue