-
Notifications
You must be signed in to change notification settings - Fork 249
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
feat(auth): Add returnOobLink to the ActionCodeSettings #502
base: dev
Are you sure you want to change the base?
Conversation
Hi @Dal-Papa Thank you for your patience on this. The Admin SDKs currently do not support sending email action links. Setting firebase-admin-go/auth/email_action_links.go Line 119 in 23a1f17
If you are looking to generate email action links the SDK already supports that and you can use your own email API to send out the emails. |
@lahirumaramba : Either you read the code wrong or you used it wrong but I was able to make Firebase send me an email with my version of the code. firebase-admin-go/auth/email_action_links.go Line 119 in 23a1f17
This is overwritten by the settings object so therefore it becomes false and hence it sends an email. Please consider this PR, we are using the fork in the meantime. |
Hi @Dal-Papa , just to clarify, you are exposing ReturnOObLink in ActionCodeSettings, so you can override to false, in case you want the email to be sent automatically, correct? That makes sense, however, I am curious about the use-case.. typically the email verification/password reset etc are triggered by the client, so maybe more suitable in the client SDKs? Can you explain how it is useful in admin SDKs? Happy to move forward on this, but would like to better understand the scenario. Thanks! |
That's correct ! We do this so we can make a few checks on the account in the backend before sending such link (i.e. if the account isn't banned or if their email has been verified in the past). |
auth/email_action_links_test.go
Outdated
@@ -40,6 +40,7 @@ var testActionCodeSettings = &ActionCodeSettings{ | |||
AndroidPackageName: "com.example.android", | |||
AndroidInstallApp: true, | |||
AndroidMinimumVersion: "6", | |||
ReturnOobLink: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this in the base testActionCodeSettings struct? We need a test case to verify that if this field is not specified, returnOobLink is still set to true, due to sdk implementation.
I suggest adding a new test case in the newly added test, see my other comment. Thanks!
auth/email_action_links_test.go
Outdated
func TestEmailVerificationSendEmail(t *testing.T) { | ||
s := echoServer(testActionLinkResponse, t) | ||
defer s.Close() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this "TestEmailVerificationCustomOobLinkSettings" or similar?
Then, we can add 2 cases:
cases := []bool{true, false}
testActionCodeSettingsCustom := map[string]interface{}{}
// make a copy to avoid modifying the base maps.
for k, v := range testActionCodeSettings {
testActionCodeSettingsCustom[k] = v
}
testActionCodeSettingsMapCustom := map[string]interface{}{}
for k, v := range testActionCodeSettingsMapCustom {
testActionCodeSettingsMapCustom[k] = v
}
for _, returnOobLink := range cases {
testActionCodeSettingsCustom.ReturnOobLink = returnOobLink
testActionCodeSettingsCustomMap["returnOobLink"] = returnOobLink
link, err := s.Client.EmailVerificationLink(..., testActionCodeSettingsCustom)
...
...
}
It would be great if you can add a similar test for EmailSignInLink and PasswordReset too. Thanks!
Thanks! Left a couple of comments in the unit test, LGTM otherwise. |
I went ahead and fixed all the tests that were using the settings, let me know if that's not what you had in mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! We are working on the API review doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the changes! Left 2 more comments (sorry for the back and forth). Other than that, LGTM to me.
auth/email_action_links_test.go
Outdated
if link != testActionLink { | ||
t.Errorf("EmailVerificationLinkWithSettings() = %q; want = %q", link, testActionLink) | ||
} | ||
cases := []bool{true, false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we can make this a list of testActionCodeSettings and testActionCodeSettingsMap instead, so we also test the "unset" case. Added some sample here, to illustrate what i mean.. (I did not verify that this compiles)
sendEmailLinkValues := []string{"true", "false", "unset"}
testActionCodeSettingsCases := []ActionCodeSettings{}
testActionCodeSettingsMapCases := []map[string]interface{}{}
for _, val := range sendEmailLinkValues {
settings, settingsMap:= getCopiesOfTestSettings(testActionCodeSettings,
testActionCodeSettingsMap)
switch(val) {
case "true":
settings.SendEmailLink = true;
settingsMap["returnOobLink"] = false;
case "false":
settings.SendEmailLink = false;
settingsMap["returnOobLink"] = true;
case "unset":
}
testActionCodeSettingsCases = append(testActionCodeSettingsCases, settings)
testActionCodeSettingsMapCases = append(testActionCodeSettingsMapCases, settingsMap)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -58,6 +59,7 @@ func (settings *ActionCodeSettings) toMap() (map[string]interface{}, error) { | |||
if err := json.Unmarshal(b, &result); err != nil { | |||
return nil, err | |||
} | |||
result["returnOobLink"] = !settings.SendEmailLink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment here like : "Since SendEmailLink defaults to true, we will always set "returnOobLink" to false by default, this means no email is sent out in the defautl case".
And we can remove the "returnOobLink" : true
setting in line 121?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this after several weeks - can you remind me how SendEmailLink defaults to true? I think the comment should be:
"Since SendEmailLink defaults to false, we will always set "returnOobLink" to true by default, this means no email is sent out in the default case".
Apologies for the mistake in my earlier comment.
- Release 4.12.0
This reverts commit 32af2b8.
Hey @prameshj & @lahirumaramba ! I've fixed your comments and I've recently merged the latest changes, would you mind taking a look so we can merge this old PR ? 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, except one comment about fixing a code comment. Thanks for your patience!
@@ -58,6 +59,7 @@ func (settings *ActionCodeSettings) toMap() (map[string]interface{}, error) { | |||
if err := json.Unmarshal(b, &result); err != nil { | |||
return nil, err | |||
} | |||
result["returnOobLink"] = !settings.SendEmailLink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this after several weeks - can you remind me how SendEmailLink defaults to true? I think the comment should be:
"Since SendEmailLink defaults to false, we will always set "returnOobLink" to true by default, this means no email is sent out in the default case".
Apologies for the mistake in my earlier comment.
any updates on when this will be merged? |
@prameshj : I've updated to the latest upstream branch and fixed the comment. Please take a look. |
@lahirumaramba : It looks like @prameshj is AWOL, can you please take over ? |
@jonathanedey : You seem like someone who's still active here, can you please take a look ? |
Discussion
#501
Testing
API Changes
us make Firebase APIs better, please propose your change in an issue so that we
can discuss it together.