diff --git a/.env.test b/.env.test index 7db07e8b6..99c8081fc 100644 --- a/.env.test +++ b/.env.test @@ -7,4 +7,5 @@ SMTP_PORT=2525 SMTP_USERNAME=test SMTP_PASSWORD=test SENDER_EMAIL="info@authorizer.dev" +SENDER_NAME="Authorizer" AWS_REGION=ap-south-1 \ No newline at end of file diff --git a/dashboard/src/components/EnvComponents/EmailConfiguration.tsx b/dashboard/src/components/EnvComponents/EmailConfiguration.tsx index 61164e5d0..eb93d5385 100644 --- a/dashboard/src/components/EnvComponents/EmailConfiguration.tsx +++ b/dashboard/src/components/EnvComponents/EmailConfiguration.tsx @@ -126,6 +126,22 @@ const EmailConfigurations = ({ /> + + + Sender Name: + +
+ +
+
); diff --git a/dashboard/src/constants.ts b/dashboard/src/constants.ts index 16f7cdb98..6bbc405ff 100644 --- a/dashboard/src/constants.ts +++ b/dashboard/src/constants.ts @@ -19,6 +19,7 @@ export const TextInputType = { SMTP_USERNAME: 'SMTP_USERNAME', SMTP_LOCAL_NAME: 'SMTP_LOCAL_NAME', SENDER_EMAIL: 'SENDER_EMAIL', + SENDER_NAME: 'SENDER_NAME', ORGANIZATION_NAME: 'ORGANIZATION_NAME', ORGANIZATION_LOGO: 'ORGANIZATION_LOGO', DATABASE_NAME: 'DATABASE_NAME', @@ -143,6 +144,7 @@ export interface envVarTypes { SMTP_PASSWORD: string; SMTP_LOCAL_NAME: string; SENDER_EMAIL: string; + SENDER_NAME: string; ALLOWED_ORIGINS: [string] | []; ORGANIZATION_NAME: string; ORGANIZATION_LOGO: string; diff --git a/dashboard/src/graphql/queries/index.ts b/dashboard/src/graphql/queries/index.ts index 5202023d6..f6667e829 100644 --- a/dashboard/src/graphql/queries/index.ts +++ b/dashboard/src/graphql/queries/index.ts @@ -50,6 +50,7 @@ export const EnvVariablesQuery = ` SMTP_PASSWORD SMTP_LOCAL_NAME SENDER_EMAIL + SENDER_NAME ALLOWED_ORIGINS ORGANIZATION_NAME ORGANIZATION_LOGO diff --git a/dashboard/src/pages/Environment.tsx b/dashboard/src/pages/Environment.tsx index 98bb8d70a..05c0d0c2a 100644 --- a/dashboard/src/pages/Environment.tsx +++ b/dashboard/src/pages/Environment.tsx @@ -70,6 +70,7 @@ const Environment = () => { SMTP_PASSWORD: '', SMTP_LOCAL_NAME: '', SENDER_EMAIL: '', + SENDER_NAME: '', ALLOWED_ORIGINS: [], ORGANIZATION_NAME: '', ORGANIZATION_LOGO: '', diff --git a/server/constants/env.go b/server/constants/env.go index 8835c7f6f..f9d7561d2 100644 --- a/server/constants/env.go +++ b/server/constants/env.go @@ -62,6 +62,8 @@ const ( EnvKeySmtpLocalName = "SMTP_LOCAL_NAME" // EnvKeySenderEmail key for env variable SENDER_EMAIL EnvKeySenderEmail = "SENDER_EMAIL" + // EnvKeySenderName key for env variable SENDER_NAME + EnvKeySenderName = "SENDER_NAME" // EnvKeyIsEmailServiceEnabled key for env variable IS_EMAIL_SERVICE_ENABLED EnvKeyIsEmailServiceEnabled = "IS_EMAIL_SERVICE_ENABLED" // EnvKeyAppCookieSecure key for env variable APP_COOKIE_SECURE diff --git a/server/email/email.go b/server/email/email.go index 5120d052b..1b7d84d1a 100644 --- a/server/email/email.go +++ b/server/email/email.go @@ -103,6 +103,12 @@ func SendEmail(to []string, event string, data map[string]interface{}) error { return err } + senderName, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeySenderName) + if err != nil { + log.Errorf("Error while getting sender name from env variable: %v", err) + return err + } + smtpPort, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeySmtpPort) if err != nil { log.Errorf("Error while getting smtp port from env variable: %v", err) @@ -139,7 +145,7 @@ func SendEmail(to []string, event string, data map[string]interface{}) error { return err } - m.SetHeader("From", senderEmail) + m.SetAddressHeader("From", senderEmail, senderName) m.SetHeader("To", to...) m.SetHeader("Subject", tmp.Subject) m.SetBody("text/html", tmp.Template) diff --git a/server/env/env.go b/server/env/env.go index 1528a4cbb..0340c321c 100644 --- a/server/env/env.go +++ b/server/env/env.go @@ -57,6 +57,7 @@ func InitAllEnv() error { osSmtpPassword := os.Getenv(constants.EnvKeySmtpPassword) osSmtpLocalName := os.Getenv(constants.EnvKeySmtpLocalName) osSenderEmail := os.Getenv(constants.EnvKeySenderEmail) + osSenderName := os.Getenv(constants.EnvKeySenderName) osJwtType := os.Getenv(constants.EnvKeyJwtType) osJwtSecret := os.Getenv(constants.EnvKeyJwtSecret) osJwtPrivateKey := os.Getenv(constants.EnvKeyJwtPrivateKey) @@ -257,6 +258,13 @@ func InitAllEnv() error { envData[constants.EnvKeySenderEmail] = osSenderEmail } + if val, ok := envData[constants.EnvKeySenderName]; !ok || val == "" { + envData[constants.EnvKeySenderName] = osSenderName + } + if osSenderName != "" && envData[constants.EnvKeySenderName] != osSenderName { + envData[constants.EnvKeySenderName] = osSenderName + } + algoVal, ok := envData[constants.EnvKeyJwtType] algo := "" if !ok || algoVal == "" { diff --git a/server/graph/generated/generated.go b/server/graph/generated/generated.go index 93cfdf2cb..2ecd7b2d9 100644 --- a/server/graph/generated/generated.go +++ b/server/graph/generated/generated.go @@ -128,6 +128,7 @@ type ComplexityRoot struct { SMTPPort func(childComplexity int) int SMTPUsername func(childComplexity int) int SenderEmail func(childComplexity int) int + SenderName func(childComplexity int) int TwitterClientID func(childComplexity int) int TwitterClientSecret func(childComplexity int) int } @@ -895,6 +896,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Env.SenderEmail(childComplexity), true + case "Env.SENDER_NAME": + if e.complexity.Env.SenderName == nil { + break + } + + return e.complexity.Env.SenderName(childComplexity), true + case "Env.TWITTER_CLIENT_ID": if e.complexity.Env.TwitterClientID == nil { break @@ -2203,6 +2211,7 @@ type Env { SMTP_PASSWORD: String SMTP_LOCAL_NAME: String SENDER_EMAIL: String + SENDER_NAME: String JWT_TYPE: String JWT_SECRET: String JWT_PRIVATE_KEY: String @@ -2320,6 +2329,7 @@ input UpdateEnvInput { SMTP_PASSWORD: String SMTP_LOCAL_NAME: String SENDER_EMAIL: String + SENDER_NAME: String JWT_TYPE: String JWT_SECRET: String JWT_PRIVATE_KEY: String @@ -4795,6 +4805,47 @@ func (ec *executionContext) fieldContext_Env_SENDER_EMAIL(ctx context.Context, f return fc, nil } +func (ec *executionContext) _Env_SENDER_NAME(ctx context.Context, field graphql.CollectedField, obj *model.Env) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Env_SENDER_NAME(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SenderName, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2áš–string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Env_SENDER_NAME(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Env", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Env_JWT_TYPE(ctx context.Context, field graphql.CollectedField, obj *model.Env) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Env_JWT_TYPE(ctx, field) if err != nil { @@ -10280,6 +10331,8 @@ func (ec *executionContext) fieldContext_Query__env(ctx context.Context, field g return ec.fieldContext_Env_SMTP_LOCAL_NAME(ctx, field) case "SENDER_EMAIL": return ec.fieldContext_Env_SENDER_EMAIL(ctx, field) + case "SENDER_NAME": + return ec.fieldContext_Env_SENDER_NAME(ctx, field) case "JWT_TYPE": return ec.fieldContext_Env_JWT_TYPE(ctx, field) case "JWT_SECRET": @@ -16276,7 +16329,7 @@ func (ec *executionContext) unmarshalInputUpdateEnvInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"ACCESS_TOKEN_EXPIRY_TIME", "ADMIN_SECRET", "CUSTOM_ACCESS_TOKEN_SCRIPT", "OLD_ADMIN_SECRET", "SMTP_HOST", "SMTP_PORT", "SMTP_USERNAME", "SMTP_PASSWORD", "SMTP_LOCAL_NAME", "SENDER_EMAIL", "JWT_TYPE", "JWT_SECRET", "JWT_PRIVATE_KEY", "JWT_PUBLIC_KEY", "ALLOWED_ORIGINS", "APP_URL", "RESET_PASSWORD_URL", "APP_COOKIE_SECURE", "ADMIN_COOKIE_SECURE", "DISABLE_EMAIL_VERIFICATION", "DISABLE_BASIC_AUTHENTICATION", "DISABLE_MAGIC_LINK_LOGIN", "DISABLE_LOGIN_PAGE", "DISABLE_SIGN_UP", "DISABLE_REDIS_FOR_ENV", "DISABLE_STRONG_PASSWORD", "DISABLE_MULTI_FACTOR_AUTHENTICATION", "ENFORCE_MULTI_FACTOR_AUTHENTICATION", "ROLES", "PROTECTED_ROLES", "DEFAULT_ROLES", "JWT_ROLE_CLAIM", "GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET", "GITHUB_CLIENT_ID", "GITHUB_CLIENT_SECRET", "FACEBOOK_CLIENT_ID", "FACEBOOK_CLIENT_SECRET", "LINKEDIN_CLIENT_ID", "LINKEDIN_CLIENT_SECRET", "APPLE_CLIENT_ID", "APPLE_CLIENT_SECRET", "TWITTER_CLIENT_ID", "TWITTER_CLIENT_SECRET", "MICROSOFT_CLIENT_ID", "MICROSOFT_CLIENT_SECRET", "MICROSOFT_ACTIVE_DIRECTORY_TENANT_ID", "ORGANIZATION_NAME", "ORGANIZATION_LOGO", "DEFAULT_AUTHORIZE_RESPONSE_TYPE", "DEFAULT_AUTHORIZE_RESPONSE_MODE"} + fieldsInOrder := [...]string{"ACCESS_TOKEN_EXPIRY_TIME", "ADMIN_SECRET", "CUSTOM_ACCESS_TOKEN_SCRIPT", "OLD_ADMIN_SECRET", "SMTP_HOST", "SMTP_PORT", "SMTP_USERNAME", "SMTP_PASSWORD", "SMTP_LOCAL_NAME", "SENDER_EMAIL", "SENDER_NAME", "JWT_TYPE", "JWT_SECRET", "JWT_PRIVATE_KEY", "JWT_PUBLIC_KEY", "ALLOWED_ORIGINS", "APP_URL", "RESET_PASSWORD_URL", "APP_COOKIE_SECURE", "ADMIN_COOKIE_SECURE", "DISABLE_EMAIL_VERIFICATION", "DISABLE_BASIC_AUTHENTICATION", "DISABLE_MAGIC_LINK_LOGIN", "DISABLE_LOGIN_PAGE", "DISABLE_SIGN_UP", "DISABLE_REDIS_FOR_ENV", "DISABLE_STRONG_PASSWORD", "DISABLE_MULTI_FACTOR_AUTHENTICATION", "ENFORCE_MULTI_FACTOR_AUTHENTICATION", "ROLES", "PROTECTED_ROLES", "DEFAULT_ROLES", "JWT_ROLE_CLAIM", "GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET", "GITHUB_CLIENT_ID", "GITHUB_CLIENT_SECRET", "FACEBOOK_CLIENT_ID", "FACEBOOK_CLIENT_SECRET", "LINKEDIN_CLIENT_ID", "LINKEDIN_CLIENT_SECRET", "APPLE_CLIENT_ID", "APPLE_CLIENT_SECRET", "TWITTER_CLIENT_ID", "TWITTER_CLIENT_SECRET", "MICROSOFT_CLIENT_ID", "MICROSOFT_CLIENT_SECRET", "MICROSOFT_ACTIVE_DIRECTORY_TENANT_ID", "ORGANIZATION_NAME", "ORGANIZATION_LOGO", "DEFAULT_AUTHORIZE_RESPONSE_TYPE", "DEFAULT_AUTHORIZE_RESPONSE_MODE"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -16363,6 +16416,14 @@ func (ec *executionContext) unmarshalInputUpdateEnvInput(ctx context.Context, ob if err != nil { return it, err } + case "SENDER_NAME": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("SENDER_NAME")) + it.SenderName, err = ec.unmarshalOString2áš–string(ctx, v) + if err != nil { + return it, err + } case "JWT_TYPE": var err error @@ -17412,6 +17473,10 @@ func (ec *executionContext) _Env(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = ec._Env_SENDER_EMAIL(ctx, field, obj) + case "SENDER_NAME": + + out.Values[i] = ec._Env_SENDER_NAME(ctx, field, obj) + case "JWT_TYPE": out.Values[i] = ec._Env_JWT_TYPE(ctx, field, obj) diff --git a/server/graph/model/models_gen.go b/server/graph/model/models_gen.go index 3651ca980..bdc78a8de 100644 --- a/server/graph/model/models_gen.go +++ b/server/graph/model/models_gen.go @@ -77,6 +77,7 @@ type Env struct { SMTPPassword *string `json:"SMTP_PASSWORD"` SMTPLocalName *string `json:"SMTP_LOCAL_NAME"` SenderEmail *string `json:"SENDER_EMAIL"` + SenderName *string `json:"SENDER_NAME"` JwtType *string `json:"JWT_TYPE"` JwtSecret *string `json:"JWT_SECRET"` JwtPrivateKey *string `json:"JWT_PRIVATE_KEY"` @@ -321,6 +322,7 @@ type UpdateEnvInput struct { SMTPPassword *string `json:"SMTP_PASSWORD"` SMTPLocalName *string `json:"SMTP_LOCAL_NAME"` SenderEmail *string `json:"SENDER_EMAIL"` + SenderName *string `json:"SENDER_NAME"` JwtType *string `json:"JWT_TYPE"` JwtSecret *string `json:"JWT_SECRET"` JwtPrivateKey *string `json:"JWT_PRIVATE_KEY"` diff --git a/server/graph/schema.graphqls b/server/graph/schema.graphqls index 9a81d95e5..15b5cc9cd 100644 --- a/server/graph/schema.graphqls +++ b/server/graph/schema.graphqls @@ -118,6 +118,7 @@ type Env { SMTP_PASSWORD: String SMTP_LOCAL_NAME: String SENDER_EMAIL: String + SENDER_NAME: String JWT_TYPE: String JWT_SECRET: String JWT_PRIVATE_KEY: String @@ -235,6 +236,7 @@ input UpdateEnvInput { SMTP_PASSWORD: String SMTP_LOCAL_NAME: String SENDER_EMAIL: String + SENDER_NAME: String JWT_TYPE: String JWT_SECRET: String JWT_PRIVATE_KEY: String diff --git a/server/resolvers/env.go b/server/resolvers/env.go index 92226af29..4378c983a 100644 --- a/server/resolvers/env.go +++ b/server/resolvers/env.go @@ -89,6 +89,9 @@ func EnvResolver(ctx context.Context) (*model.Env, error) { if val, ok := store[constants.EnvKeySenderEmail]; ok { res.SenderEmail = refs.NewStringRef(val.(string)) } + if val, ok := store[constants.EnvKeySenderName]; ok { + res.SenderName = refs.NewStringRef(val.(string)) + } if val, ok := store[constants.EnvKeySmtpLocalName]; ok { res.SMTPLocalName = refs.NewStringRef(val.(string)) }