feat: Add support for providers to validate their options at loading time (#8853)
* feat: Add support for providers to validate their options at loading time * fix missing removal * fix integration tests * add tests
This commit is contained in:
@@ -19,12 +19,25 @@ export class GoogleAuthService extends AbstractAuthModuleProvider {
|
||||
protected config_: LocalServiceConfig
|
||||
protected logger_: Logger
|
||||
|
||||
static validateOptions(options: GoogleAuthProviderOptions) {
|
||||
if (!options.clientID) {
|
||||
throw new Error("Google clientID is required")
|
||||
}
|
||||
|
||||
if (!options.clientSecret) {
|
||||
throw new Error("Google clientSecret is required")
|
||||
}
|
||||
|
||||
if (!options.callbackURL) {
|
||||
throw new Error("Google callbackUrl is required")
|
||||
}
|
||||
}
|
||||
|
||||
constructor(
|
||||
{ logger }: InjectedDependencies,
|
||||
options: GoogleAuthProviderOptions
|
||||
) {
|
||||
super({}, { provider: "google", displayName: "Google Authentication" })
|
||||
this.validateConfig(options)
|
||||
this.config_ = options
|
||||
this.logger_ = logger
|
||||
}
|
||||
@@ -173,18 +186,4 @@ export class GoogleAuthService extends AbstractAuthModuleProvider {
|
||||
|
||||
return { success: true, location: authUrl.toString() }
|
||||
}
|
||||
|
||||
private validateConfig(config: LocalServiceConfig) {
|
||||
if (!config.clientID) {
|
||||
throw new Error("Google clientID is required")
|
||||
}
|
||||
|
||||
if (!config.clientSecret) {
|
||||
throw new Error("Google clientSecret is required")
|
||||
}
|
||||
|
||||
if (!config.callbackURL) {
|
||||
throw new Error("Google callbackUrl is required")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user