Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make google auth optional on server side #508

Merged
merged 3 commits into from
Jul 4, 2023
Merged

Conversation

charlesBochet
Copy link
Member

@charlesBochet charlesBochet commented Jul 4, 2023

In this PR, I'm making the following changes:

  • adding a AUTH_GOOGLE_ENABLED boolean to .env. If set to true, AUTH_GOOGLE_CLIENT_ID, AUTH_GOOGLE_CLIENT_SECRET and AUTH_GOOGLE_CALLBACK_URL will be required. If missing or set to any other value, these won't be required
  • if AUTH_GOOGLE_ENABLED is set to false, GoogleStrategy is set with placeholder values for credentials and google auth controller routes are disabled through a GoogleProviderEnabledGuard

Additionally:

  • rename storage env variables to be less confusing: if STORAGE_TYPE=local, STORAGE_LOCAL_PATH is required / if STORAGE_TYPE=S3, STORAGE_S3_REGION and STORAGE_S3_NAME are required

clientID: environmentService.getAuthGoogleClientId(),
clientSecret: environmentService.getAuthGoogleClientSecret(),
callbackURL: environmentService.getAuthGoogleCallbackUrl(),
clientID: isAuthGoogleEnabled
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magrinj @emilienchvt not very proud of these disabled but super() has to be called.
Another solution would be to not register the strategy using DynamicModules

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not extremely better, but disabledClientId, disabledClientSecret and disabledCallbackUrl might be less generic

}

export function validate(config: Record<string, unknown>) {
const validatedConfig = plainToClass(EnvironmentVariables, config, {
enableImplicitConversion: true,
enableImplicitConversion: false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have disabled this because it was casting ENV_VARIABLE=false to TRUE...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my other comment below

Copy link
Contributor

@emilienchvt emilienchvt Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, maybe some ideas here: typestack/class-transformer#550
The workarounds described do not look too different from yours

Copy link
Member Author

@charlesBochet charlesBochet Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice link did not find it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use Transform instead of disabling this, because it's going to stop inferring types on all other env variables


return {
bucketName,
bucketName: bucketName ?? '',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only moving the problem to here. I believe the S3Module should not be instanciated if S3 is not configured in env variables. I would encapsulated LocalDriver and S3Driver behind one common FileStorage Interface.
To be discussed and treated in another PR!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we track this as a new task ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll discuss it with Jeremy tomorrow and create a task based on discussion!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created here: #510 we can discuss it tomorrow

@@ -38,34 +39,44 @@ export class EnvironmentVariables {
@IsUrl({ require_tld: false })
FRONT_AUTH_CALLBACK_URL: string;

@IsString()
@Transform(({ value }) => value.toLowerCase() === 'true')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I would like the environment validation to throw if the provided value is not either 'true'/'TRUE'/'1' or 'false'/'FALSE'/'0' and then convert it to a boolean. I'm unsure how to do that properly.
I'm thinking about a pre-process of environment variables maybe a little bit more sophisticated than @Transform or enableImplicitConversion

@charlesBochet charlesBochet merged commit 2afe933 into main Jul 4, 2023
@charlesBochet charlesBochet deleted the oauth-optional branch July 4, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants