Skip to content

Commit e690066

Browse files
committed
fix(server):give higher preference to redirect_uri
While using forgot_password redirect URI was ignored if not present Resolves #275
1 parent 6e09307 commit e690066

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

server/resolvers/forgot_password.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
6262
log.Debug("Failed to generate nonce: ", err)
6363
return res, err
6464
}
65-
redirectURL := parsers.GetAppURL(gc)
65+
redirectURI := parsers.GetAppURL(gc)
6666
if strings.TrimSpace(refs.StringValue(params.RedirectURI)) != "" {
67-
redirectURL = refs.StringValue(params.RedirectURI)
67+
redirectURI = refs.StringValue(params.RedirectURI)
6868
}
6969

70-
verificationToken, err := token.CreateVerificationToken(params.Email, constants.VerificationTypeForgotPassword, hostname, nonceHash, redirectURL)
70+
verificationToken, err := token.CreateVerificationToken(params.Email, constants.VerificationTypeForgotPassword, hostname, nonceHash, redirectURI)
7171
if err != nil {
7272
log.Debug("Failed to create verification token", err)
7373
return res, err
@@ -78,7 +78,7 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
7878
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
7979
Email: params.Email,
8080
Nonce: nonceHash,
81-
RedirectURI: redirectURL,
81+
RedirectURI: redirectURI,
8282
})
8383
if err != nil {
8484
log.Debug("Failed to add verification request", err)
@@ -89,7 +89,7 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
8989
go email.SendEmail([]string{params.Email}, constants.VerificationTypeForgotPassword, map[string]interface{}{
9090
"user": user.ToMap(),
9191
"organization": utils.GetOrganization(),
92-
"verification_url": utils.GetForgotPasswordURL(verificationToken, hostname),
92+
"verification_url": utils.GetForgotPasswordURL(verificationToken, hostname, redirectURI),
9393
})
9494

9595
res = &model.Response{

server/utils/common.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,22 @@ func GetOrganization() map[string]interface{} {
8181
}
8282

8383
// GetForgotPasswordURL to get url for given token and hostname
84-
func GetForgotPasswordURL(token, hostname string) string {
85-
resetPasswordUrl, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyResetPasswordURL)
86-
if err != nil {
87-
return ""
88-
}
89-
if resetPasswordUrl == "" {
90-
if err := memorystore.Provider.UpdateEnvVariable(constants.EnvKeyResetPasswordURL, hostname+"/app/reset-password"); err != nil {
84+
func GetForgotPasswordURL(token, hostname, redirectURI string) string {
85+
resetPasswordURL := redirectURI
86+
87+
if resetPasswordURL == "" {
88+
resetPasswordURL, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyResetPasswordURL)
89+
if err != nil {
9190
return ""
9291
}
92+
if resetPasswordURL == "" {
93+
if err := memorystore.Provider.UpdateEnvVariable(constants.EnvKeyResetPasswordURL, hostname+"/app/reset-password"); err != nil {
94+
return ""
95+
}
96+
}
9397
}
94-
verificationURL := resetPasswordUrl + "?token=" + token
98+
99+
verificationURL := resetPasswordURL + "?token=" + token
95100
return verificationURL
96101
}
97102

0 commit comments

Comments
 (0)