Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions server/core/lib/auth/external-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function onExternalUserAuthenticated (options: {
return
}

const { res, externalRedirectUri } = authResult
const { res, externalRedirectUri, returnJsonNoRedirect } = authResult

if (!isAuthResultValid(npmName, authName, authResult)) {
res.redirect('/login?externalAuthError=true')
Expand Down Expand Up @@ -76,7 +76,9 @@ async function onExternalUserAuthenticated (options: {
}
}

if (externalRedirectUri) {
if(returnJsonNoRedirect) {
res.status(200).json({ externalAuthToken: bypassToken, username: user.username })
} else if (externalRedirectUri) {
const url = new URL(externalRedirectUri)
url.searchParams.set('externalAuthToken', bypassToken)
url.searchParams.set('username', user.username)
Expand Down
2 changes: 2 additions & 0 deletions server/core/types/plugins/register-server-auth.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface RegisterServerExternalAuthenticatedResult extends RegisterServe
res: express.Response
// Redirect the user to this external URI after the external auth has been verified.
externalRedirectUri?: string
// Respond with a 200 OK and JSON body instead of redirecting, to allow API access.
returnJsonNoRedirect?: boolean
}

interface RegisterServerAuthBase {
Expand Down
Loading