uberf-7350: add more oauth logs (#5879)

This commit is contained in:
Alexey Zinoviev 2024-06-21 06:13:31 +04:00 committed by GitHub
parent 182d108b87
commit adb286676e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -38,7 +38,7 @@ export function registerGithub (
router.get('/auth/github', async (ctx, next) => { router.get('/auth/github', async (ctx, next) => {
measureCtx.info('try auth via', { provider: 'github' }) measureCtx.info('try auth via', { provider: 'github' })
const host = getHost(ctx.request.headers) const host = getHost(ctx.request.headers)
const branding = host !== undefined ? brandings[host]?.key ?? '' : '' const branding = host !== undefined ? brandings[host]?.key ?? undefined : undefined
const state = encodeURIComponent( const state = encodeURIComponent(
JSON.stringify({ JSON.stringify({
inviteId: ctx.query?.inviteId, inviteId: ctx.query?.inviteId,

View File

@ -38,7 +38,7 @@ export function registerGoogle (
router.get('/auth/google', async (ctx, next) => { router.get('/auth/google', async (ctx, next) => {
measureCtx.info('try auth via', { provider: 'google' }) measureCtx.info('try auth via', { provider: 'google' })
const host = getHost(ctx.request.headers) const host = getHost(ctx.request.headers)
const branding = host !== undefined ? brandings[host]?.key ?? '' : '' const branding = host !== undefined ? brandings[host]?.key ?? undefined : undefined
const state = encodeURIComponent( const state = encodeURIComponent(
JSON.stringify({ JSON.stringify({
inviteId: ctx.query?.inviteId, inviteId: ctx.query?.inviteId,
@ -53,14 +53,19 @@ export function registerGoogle (
redirectURL, redirectURL,
async (ctx, next) => { async (ctx, next) => {
const state = safeParseAuthState(ctx.query?.state) const state = safeParseAuthState(ctx.query?.state)
measureCtx.info('Auth state', { state })
const branding = getBranding(brandings, state?.branding) const branding = getBranding(brandings, state?.branding)
measureCtx.info('With branding', { branding })
const failureRedirect = concatLink(branding?.front ?? frontUrl, '/login')
measureCtx.info('With failure redirect', { failureRedirect })
passport.authenticate('google', { passport.authenticate('google', {
failureRedirect: concatLink(branding?.front ?? frontUrl, '/login'), failureRedirect,
session: true session: true
})(ctx, next) })(ctx, next)
}, },
async (ctx, next) => { async (ctx, next) => {
measureCtx.info('Provider auth success', { type: 'google', user: ctx.state?.user })
const email = ctx.state.user.emails?.[0]?.value const email = ctx.state.user.emails?.[0]?.value
const first = ctx.state.user.name.givenName const first = ctx.state.user.name.givenName
const last = ctx.state.user.name.familyName const last = ctx.state.user.name.familyName