feat(server): allow to use ssl on server (#8722)

This commit is contained in:
Antoine Moreaux
2024-11-26 16:30:51 +01:00
committed by GitHub
parent 08f163592b
commit eb39288583
8 changed files with 172 additions and 17 deletions

View File

@ -103,8 +103,9 @@ export class SSOAuthController {
);
} catch (err) {
// TODO: improve error management
res.status(403).send(err.message);
res.redirect(`${this.environmentService.get('FRONT_BASE_URL')}/verify`);
res
.status(403)
.redirect(`${this.environmentService.get('FRONT_BASE_URL')}/verify`);
}
}

View File

@ -127,13 +127,12 @@ export class EnvironmentVariables {
PG_SSL_ALLOW_SELF_SIGNED = false;
// Frontend URL
@IsUrl({ require_tld: false })
@IsUrl({ require_tld: false, require_protocol: true })
FRONT_BASE_URL: string;
// Server URL
@IsUrl({ require_tld: false })
@IsUrl({ require_tld: false, require_protocol: true })
@IsOptional()
SERVER_URL: string;
SERVER_URL = 'http://localhost:3000';
@IsString()
APP_SECRET: string;
@ -166,10 +165,6 @@ export class EnvironmentVariables {
INVITATION_TOKEN_EXPIRES_IN = '30d';
// Auth
@IsUrl({ require_tld: false })
@IsOptional()
FRONT_AUTH_CALLBACK_URL: string;
@CastToBoolean()
@IsOptional()
@IsBoolean()
@ -198,11 +193,11 @@ export class EnvironmentVariables {
@ValidateIf((env) => env.AUTH_MICROSOFT_ENABLED)
AUTH_MICROSOFT_CLIENT_SECRET: string;
@IsUrl({ require_tld: false })
@IsUrl({ require_tld: false, require_protocol: true })
@ValidateIf((env) => env.AUTH_MICROSOFT_ENABLED)
AUTH_MICROSOFT_CALLBACK_URL: string;
@IsUrl({ require_tld: false })
@IsUrl({ require_tld: false, require_protocol: true })
@ValidateIf((env) => env.AUTH_MICROSOFT_ENABLED)
AUTH_MICROSOFT_APIS_CALLBACK_URL: string;
@ -219,7 +214,7 @@ export class EnvironmentVariables {
@ValidateIf((env) => env.AUTH_GOOGLE_ENABLED)
AUTH_GOOGLE_CLIENT_SECRET: string;
@IsUrl({ require_tld: false })
@IsUrl({ require_tld: false, require_protocol: true })
@ValidateIf((env) => env.AUTH_GOOGLE_ENABLED)
AUTH_GOOGLE_CALLBACK_URL: string;
@ -475,6 +470,15 @@ export class EnvironmentVariables {
// milliseconds
@CastToPositiveNumber()
SERVERLESS_FUNCTION_EXEC_THROTTLE_TTL = 1000;
// SSL
@IsString()
@ValidateIf((env) => env.SERVER_URL.startsWith('https'))
SSL_KEY_PATH: string;
@IsString()
@ValidateIf((env) => env.SERVER_URL.startsWith('https'))
SSL_CERT_PATH: string;
}
export const validate = (

View File

@ -209,7 +209,11 @@ export class SSOService {
buildIssuerURL(
identityProvider: Pick<WorkspaceSSOIdentityProvider, 'id' | 'type'>,
) {
return `${this.environmentService.get('SERVER_URL')}/auth/${identityProvider.type.toLowerCase()}/login/${identityProvider.id}`;
const authorizationUrl = new URL(this.environmentService.get('SERVER_URL'));
authorizationUrl.pathname = `/auth/${identityProvider.type.toLowerCase()}/login/${identityProvider.id}`;
return authorizationUrl.toString();
}
private isOIDCIdentityProvider(