Separate environment configs (#6597)
* Separate environment configs * wip * wip * test * plugins * test * test * .sequelizerc, unfortunately can't go through /utils/environment due to not supporting TS * docker-compose -> docker compose * fix: .local wipes .development * Add custom validation message for invalid SECRET_KEY (often confused)
This commit is contained in:
@@ -6,7 +6,6 @@ import { Profile } from "passport";
|
||||
import { Strategy as GoogleStrategy } from "passport-google-oauth2";
|
||||
import { slugifyDomain } from "@shared/utils/domains";
|
||||
import accountProvisioner from "@server/commands/accountProvisioner";
|
||||
import env from "@server/env";
|
||||
import {
|
||||
GmailAccountCreationError,
|
||||
TeamDomainRequiredError,
|
||||
@@ -19,6 +18,7 @@ import {
|
||||
getTeamFromContext,
|
||||
getClientFromContext,
|
||||
} from "@server/utils/passport";
|
||||
import env from "../env";
|
||||
|
||||
const router = new Router();
|
||||
const providerName = "google";
|
||||
|
||||
21
plugins/google/server/env.ts
Normal file
21
plugins/google/server/env.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { IsOptional } from "class-validator";
|
||||
import { Environment } from "@server/env";
|
||||
import environment from "@server/utils/environment";
|
||||
import { CannotUseWithout } from "@server/utils/validators";
|
||||
|
||||
class GooglePluginEnvironment extends Environment {
|
||||
/**
|
||||
* Google OAuth2 client credentials. To enable authentication with Google.
|
||||
*/
|
||||
@IsOptional()
|
||||
@CannotUseWithout("GOOGLE_CLIENT_SECRET")
|
||||
public GOOGLE_CLIENT_ID = this.toOptionalString(environment.GOOGLE_CLIENT_ID);
|
||||
|
||||
@IsOptional()
|
||||
@CannotUseWithout("GOOGLE_CLIENT_ID")
|
||||
public GOOGLE_CLIENT_SECRET = this.toOptionalString(
|
||||
environment.GOOGLE_CLIENT_SECRET
|
||||
);
|
||||
}
|
||||
|
||||
export default new GooglePluginEnvironment();
|
||||
18
plugins/google/server/google.ts
Normal file
18
plugins/google/server/google.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import invariant from "invariant";
|
||||
import OAuthClient from "@server/utils/oauth";
|
||||
import env from "./env";
|
||||
|
||||
export default class GoogleClient extends OAuthClient {
|
||||
endpoints = {
|
||||
authorize: "https://accounts.google.com/o/oauth2/auth",
|
||||
token: "https://accounts.google.com/o/oauth2/token",
|
||||
userinfo: "https://www.googleapis.com/oauth2/v3/userinfo",
|
||||
};
|
||||
|
||||
constructor() {
|
||||
invariant(env.GOOGLE_CLIENT_ID, "GOOGLE_CLIENT_ID is required");
|
||||
invariant(env.GOOGLE_CLIENT_SECRET, "GOOGLE_CLIENT_SECRET is required");
|
||||
|
||||
super(env.GOOGLE_CLIENT_ID, env.GOOGLE_CLIENT_SECRET);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user