useTemplates for initsso as well

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-10-22 14:04:54 +02:00
parent 44e806cf1f
commit 8c7c9c166b
No known key found for this signature in database
2 changed files with 19 additions and 6 deletions

View file

@ -106,9 +106,16 @@ export class ControllerRegistry {
try {
return await controller[handlerName](...args);
} catch (error) {
if (route.usesTemplates && error instanceof ResponseError) {
res.writeHead(error.httpStatusCode, { 'Content-Type': 'text/plain' });
return res.end(error.message);
if (route.usesTemplates) {
if (error instanceof ResponseError) {
return res
.writeHead(error.httpStatusCode, { 'Content-Type': 'text/plain' })
.send(error.message);
} else {
return res
.writeHead(500, { 'Content-Type': 'text/plain' })
.send('Internal Server Error');
}
}
throw error;
}

View file

@ -151,7 +151,9 @@ export class SamlController {
throw new AuthError('SAML Authentication failed');
} catch (error) {
if (isConnectionTestRequest) {
return res.render('sso/saml-connection-test-failed', { message: (error as Error).message });
return res.render('sso/saml-connection-test-failed', {
message: (error as Error).message,
});
}
this.eventService.emit('user-login-failed', {
userEmail: 'unknown',
@ -165,7 +167,11 @@ export class SamlController {
* Access URL for implementing SP-init SSO
* This endpoint is available if SAML is licensed and enabled
*/
@Get('/initsso', { middlewares: [samlLicensedAndEnabledMiddleware], skipAuth: true })
@Get('/initsso', {
middlewares: [samlLicensedAndEnabledMiddleware],
skipAuth: true,
usesTemplates: true,
})
async initSsoGet(req: express.Request, res: express.Response) {
let redirectUrl = '';
try {
@ -189,7 +195,7 @@ export class SamlController {
* Test SAML config
* This endpoint is available if SAML is licensed and the requestor is an instance owner
*/
@Get('/config/test', { middlewares: [samlLicensedMiddleware] })
@Get('/config/test', { middlewares: [samlLicensedMiddleware], usesTemplates: true })
@GlobalScope('saml:manage')
async configTestGet(_: AuthenticatedRequest, res: express.Response) {
return await this.handleInitSSO(res, getServiceProviderConfigTestReturnUrl());