[go: up one dir, main page]

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

feat(auth): Add returnOobLink to the ActionCodeSettings #502

Open
wants to merge 33 commits into
base: dev
Choose a base branch
from

Conversation

Dal-Papa
Copy link

Discussion

#501

Testing

  • Make sure all existing tests in the repository pass after your change. ✅
  • If you fixed a bug or added a feature, add a new test to cover your code. ✅

API Changes

  • At this time we cannot accept changes that affect the public API. If you'd like to help
    us make Firebase APIs better, please propose your change in an issue so that we
    can discuss it together.

@Dal-Papa
Copy link
Author
Dal-Papa commented Aug 1, 2022

@lahirumaramba @hiranya911 👋

@lahirumaramba lahirumaramba changed the base branch from master to dev October 17, 2022 19:55
@lahirumaramba
Copy link
Member

Hi @Dal-Papa Thank you for your patience on this. The Admin SDKs currently do not support sending email action links. Setting returnOobLink does not send the email, in-fact we already set it to true in the code below.

"returnOobLink": true,

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 lahirumaramba self-assigned this Oct 17, 2022
@Dal-Papa
Copy link
Author

@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.

"returnOobLink": true,

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.

@prameshj
Copy link

Lahiru Maramba : 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.

"returnOobLink": true,

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!

@Dal-Papa
Copy link
Author

Lahiru Maramba : 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.

"returnOobLink": true,

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).

@@ -40,6 +40,7 @@ var testActionCodeSettings = &ActionCodeSettings{
AndroidPackageName: "com.example.android",
AndroidInstallApp: true,
AndroidMinimumVersion: "6",
ReturnOobLink: true,

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!

func TestEmailVerificationSendEmail(t *testing.T) {
s := echoServer(testActionLinkResponse, t)
defer s.Close()

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!

@prameshj
Copy link

Lahiru Maramba : 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.

"returnOobLink": true,

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 Clement DAL PALU , 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).

Thanks! Left a couple of comments in the unit test, LGTM otherwise.

@Dal-Papa
Copy link
Author

Lahiru Maramba : 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.

"returnOobLink": true,

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 Clement DAL PALU , 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).

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.

@lahirumaramba
Copy link
Member

@Dal-Papa Thank you for your contribution! I definitely did misunderstood the API in my initial comment, my apologies!

@prameshj I think we need an internal API proposal for the public API change before we can merge this. Thanks!

Copy link
@prameshj prameshj left a 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.

@Dal-Papa Dal-Papa requested review from pragatimodi and lahirumaramba and removed request for pragatimodi and lahirumaramba November 23, 2022 16:08
Copy link
@prameshj prameshj left a 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.

if link != testActionLink {
t.Errorf("EmailVerificationLinkWithSettings() = %q; want = %q", link, testActionLink)
}
cases := []bool{true, false}
Copy link

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)
}

Copy link
Author

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
Copy link

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?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

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.

@Dal-Papa Dal-Papa requested review from prameshj and removed request for pragatimodi March 8, 2023 14:29
@Dal-Papa
Copy link
Author

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 ? 🙂

Copy link
@prameshj prameshj left a 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

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.

@drmaples
Copy link

any updates on when this will be merged?

@Dal-Papa
Copy link
Author
Dal-Papa commented Mar 4, 2024

@prameshj : I've updated to the latest upstream branch and fixed the comment. Please take a look.

@Dal-Papa
Copy link
Author
Dal-Papa commented Mar 6, 2024

@lahirumaramba : It looks like @prameshj is AWOL, can you please take over ?

@lahirumaramba lahirumaramba requested review from prameshj and removed request for prameshj March 12, 2024 20:11
@Dal-Papa
Copy link
Author
Dal-Papa commented Mar 30, 2024

@jonathanedey : You seem like someone who's still active here, can you please take a look ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants