Skip to content

Commit 3624f83

Browse files
Additional logging for proxyAuth.
1 parent 3f30f0b commit 3624f83

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

server/util/auth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { isUnapproved, isUnverified, loginFactors } from '@shared/user'
33
import { userRequiresMfa } from '../db/user'
44
import appConfig from './config'
55

6+
/**
7+
* Determines if a user can login.
8+
* Checks that session has required factors, user is approved, and email is verified (if required)
9+
*/
610
export function userCanLogin(user: UserDetails | undefined, amr: string[]): user is UserDetails {
711
if (!user) {
812
return false

server/util/proxyAuth.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export async function proxyAuth(url: URL, method: 'forward-auth' | 'auth-request
7070
amr = ['pwd']
7171
} else {
7272
// User not logged in, redirect to login
73+
const logInfo = {
74+
reason: 'session_not_found',
75+
url: url.href,
76+
}
77+
logger.debug(`session not found, redirect to login: ${JSON.stringify(logInfo)}`)
7378
res.redirect(redirCode, `${appConfig.APP_URL}${oidcLoginPath(appConfig.APP_URL, { redirectUrl: url.href, isProxyAuth: true })}`)
7479
res.send()
7580
return
@@ -78,6 +83,11 @@ export async function proxyAuth(url: URL, method: 'forward-auth' | 'auth-request
7883
// Check that user is approved and verified and should be able to continue
7984
if (!userCanLogin(user, amr)) {
8085
// If not, redirect to login flow, which will send to correct redirect
86+
const logInfo = {
87+
reason: 'login_not_finished',
88+
url: url.href,
89+
}
90+
logger.debug(`user has not finished login: ${JSON.stringify(logInfo)}`)
8191
res.redirect(redirCode, `${appConfig.APP_URL}${oidcLoginPath(appConfig.APP_URL, { redirectUrl: url.href, isProxyAuth: true })}`)
8292
res.send()
8393
return
@@ -86,6 +96,12 @@ export async function proxyAuth(url: URL, method: 'forward-auth' | 'auth-request
8696
// Check that proxyAuth domain does not require MFA or user is logged in with MFA already
8797
if (!!match?.mfaRequired && loginFactors(amr) < 2) {
8898
// If not, redirect to login flow, which will send to correct redirect
99+
const logInfo = {
100+
reason: 'domain_mfa_required',
101+
url: url.href,
102+
domain: match.domain,
103+
}
104+
logger.debug(`mfa required for domain: ${JSON.stringify(logInfo)}`)
89105
res.redirect(redirCode, `${appConfig.APP_URL}${oidcLoginPath(appConfig.APP_URL, { redirectUrl: url.href, isProxyAuth: true })}`)
90106
res.send()
91107
return

0 commit comments

Comments
 (0)