Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dotnet test FirebaseAdmin/FirebaseAdmin.Tests --framework net462
### Journey 2: How to Deprecate a Field/Method in an Existing API

1. **Add Deprecation Note**: Locate where the deprecated object is defined and add a deprecation warning with a note (e.g. [Obsolete("Use X instead")]).
2. **Remove Releted Tests and Update Snippets**: Because `Obsolete` warnings result in build errors, tests and snippets where the object is used should be removed or updated not no longer used the deprecated object.
2. **Suppress Obsolete Warnings**: Because `Obsolete` warnings result in build errors, tests and snippets where the object is used should be marked using `#pragma` directives to suppress warnings where the object is used.

## Critical Do's and Don'ts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ internal static ActionCodeSettings InitActionCodeSettings()
AndroidPackageName = "com.example.android",
AndroidInstallApp = true,
AndroidMinimumVersion = "12",
DynamicLinkDomain = "coolapp.page.link",
LinkDomain = "coolapp.page.link",
};
// [END init_action_code_settings]
return actionCodeSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public class AuthErrorHandlerTest
ErrorCode.NotFound,
AuthErrorCode.EmailNotFound,
},
new object[]
{
"INVALID_HOSTING_LINK_DOMAIN",
ErrorCode.InvalidArgument,
AuthErrorCode.InvalidHostingLinkDomain,
},
};

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ public class EmailActionRequestTest
new ActionCodeSettings()
{
Url = "https://example.dynamic.link",
#pragma warning disable CS0618
DynamicLinkDomain = string.Empty,
#pragma warning restore CS0618
},
},
new object[]
{
new ActionCodeSettings()
{
Url = "https://example.dynamic.link",
LinkDomain = string.Empty,
},
},
new object[]
Expand Down Expand Up @@ -84,7 +94,10 @@ public class EmailActionRequestTest
{
Url = "https://example.dynamic.link",
HandleCodeInApp = true,
#pragma warning disable CS0618
DynamicLinkDomain = "custom.page.link",
#pragma warning restore CS0618
LinkDomain = "custom.page.link",
IosBundleId = "com.example.ios",
AndroidPackageName = "com.example.android",
AndroidMinimumVersion = "6",
Expand Down Expand Up @@ -163,14 +176,17 @@ public async Task EmailVerificationLinkWithSettings()

var request = NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(
handler.LastRequestBody);
Assert.Equal(10, request.Count);
Assert.Equal(11, request.Count);
Assert.Equal("user@example.com", request["email"]);
Assert.Equal("VERIFY_EMAIL", request["requestType"]);
Assert.True((bool)request["returnOobLink"]);

Assert.Equal(ActionCodeSettings.Url, request["continueUrl"]);
Assert.True((bool)request["canHandleCodeInApp"]);
#pragma warning disable CS0618
Assert.Equal(ActionCodeSettings.DynamicLinkDomain, request["dynamicLinkDomain"]);
#pragma warning restore CS0618
Assert.Equal(ActionCodeSettings.LinkDomain, request["linkDomain"]);
Assert.Equal(ActionCodeSettings.IosBundleId, request["iOSBundleId"]);
Assert.Equal(ActionCodeSettings.AndroidPackageName, request["androidPackageName"]);
Assert.Equal(
Expand Down Expand Up @@ -229,14 +245,17 @@ public async Task PasswordResetLinkWithSettings()

var request = NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(
handler.LastRequestBody);
Assert.Equal(10, request.Count);
Assert.Equal(11, request.Count);
Assert.Equal("user@example.com", request["email"]);
Assert.Equal("PASSWORD_RESET", request["requestType"]);
Assert.True((bool)request["returnOobLink"]);

Assert.Equal(ActionCodeSettings.Url, request["continueUrl"]);
Assert.True((bool)request["canHandleCodeInApp"]);
#pragma warning disable CS0618
Assert.Equal(ActionCodeSettings.DynamicLinkDomain, request["dynamicLinkDomain"]);
#pragma warning restore CS0618
Assert.Equal(ActionCodeSettings.LinkDomain, request["linkDomain"]);
Assert.Equal(ActionCodeSettings.IosBundleId, request["iOSBundleId"]);
Assert.Equal(ActionCodeSettings.AndroidPackageName, request["androidPackageName"]);
Assert.Equal(
Expand Down Expand Up @@ -287,14 +306,17 @@ public async Task SignInWithEmailLink()

var request = NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(
handler.LastRequestBody);
Assert.Equal(10, request.Count);
Assert.Equal(11, request.Count);
Assert.Equal("user@example.com", request["email"]);
Assert.Equal("EMAIL_SIGNIN", request["requestType"]);
Assert.True((bool)request["returnOobLink"]);

Assert.Equal(ActionCodeSettings.Url, request["continueUrl"]);
Assert.True((bool)request["canHandleCodeInApp"]);
#pragma warning disable CS0618
Assert.Equal(ActionCodeSettings.DynamicLinkDomain, request["dynamicLinkDomain"]);
#pragma warning restore CS0618
Assert.Equal(ActionCodeSettings.LinkDomain, request["linkDomain"]);
Assert.Equal(ActionCodeSettings.IosBundleId, request["iOSBundleId"]);
Assert.Equal(ActionCodeSettings.AndroidPackageName, request["androidPackageName"]);
Assert.Equal(
Expand Down Expand Up @@ -351,6 +373,39 @@ public async Task InvalidDynamicLinkDomain()
Assert.Null(exception.InnerException);
}

[Fact]
public async Task InvalidHostingLinkDomain()
{
var json = $@"{{
""error"": {{
""message"": ""INVALID_HOSTING_LINK_DOMAIN"",
}}
}}";
var handler = new MockMessageHandler()
{
StatusCode = HttpStatusCode.InternalServerError,
Response = json,
};
var auth = this.CreateFirebaseAuth(handler);
var settings = new ActionCodeSettings()
{
Url = "https://example.dynamic.link",
LinkDomain = "custom.page.link",
};

var exception = await Assert.ThrowsAsync<FirebaseAuthException>(
async () => await auth.GenerateSignInWithEmailLinkAsync(
"user@example.com", settings));

Assert.Equal(ErrorCode.InvalidArgument, exception.ErrorCode);
Assert.Equal(AuthErrorCode.InvalidHostingLinkDomain, exception.AuthErrorCode);
Assert.Equal(
"The provided hosting link domain is not configured in Firebase Hosting or is not owned by the current project (INVALID_HOSTING_LINK_DOMAIN).",
exception.Message);
Assert.NotNull(exception.HttpResponse);
Assert.Null(exception.InnerException);
}

private FirebaseAuth CreateFirebaseAuth(HttpMessageHandler handler)
{
var userManager = new FirebaseUserManager(new FirebaseUserManager.Args
Expand Down
9 changes: 9 additions & 0 deletions FirebaseAdmin/FirebaseAdmin/Auth/ActionCodeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,21 @@ public sealed class ActionCodeSettings
/// </summary>
public bool HandleCodeInApp { get; set; }

/// <summary>
/// Gets or sets the hosting link domain to use for the current link if it is to be opened
/// using <c>handleCodeInApp</c>, as multiple hosting link domains can be configured per
/// project. This setting provides the ability to explicitly choose one. If none is provided,
/// the default hosting domain is used.
/// </summary>
public string LinkDomain { get; set; }

/// <summary>
/// Gets or sets the dynamic link domain to use for the current link if it is to be opened
/// using Firebase Dynamic Links, as multiple dynamic link domains can be configured per
/// project. This setting provides the ability to explicitly choose one. If none is provided,
/// the oldest domain is used by default.
/// </summary>
[System.Obsolete("DynamicLinkDomain is deprecated, use LinkDomain instead")]
public string DynamicLinkDomain { get; set; }

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions FirebaseAdmin/FirebaseAdmin/Auth/AuthErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public enum AuthErrorCode
/// </summary>
InvalidDynamicLinkDomain,

/// <summary>
/// The provided hosting link domain is not configured in Firebase Hosting or is not owned by the current project.
/// </summary>
InvalidHostingLinkDomain,

/// <summary>
/// The specified ID token has been revoked.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions FirebaseAdmin/FirebaseAdmin/Auth/AuthErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ internal sealed class AuthErrorHandler
AuthErrorCode.InvalidDynamicLinkDomain,
"Dynamic link domain specified in ActionCodeSettings is not authorized")
},
{
"INVALID_HOSTING_LINK_DOMAIN",
new ErrorInfo(
ErrorCode.InvalidArgument,
AuthErrorCode.InvalidHostingLinkDomain,
"The provided hosting link domain is not configured in Firebase Hosting or is not owned by the current project")

Choose a reason for hiding this comment

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

Are these error message same accross all SDKs? Also the message looks confusing for the developers

"Cant we just say he provided hosting link domain is not configured in Firebase Hosting for this project"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do use that same error message across the other SDKs:
https://github.com/firebase/firebase-admin-node/blob/f861260ed3035cf3a8a0af285ccc755d926f242a/src/utils/error.ts#L507.
If we wanted to change that messaging we'd likely have to mirror that in the other SDKs as well.

},
{
"PHONE_NUMBER_EXISTS",
new ErrorInfo(
Expand Down
11 changes: 11 additions & 0 deletions FirebaseAdmin/FirebaseAdmin/Auth/Users/EmailActionLinkRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ private EmailActionLinkRequest(string type, string email, ActionCodeSettings set
{
this.Url = settings.Url;
this.HandleCodeInApp = settings.HandleCodeInApp;
#pragma warning disable CS0618
this.DynamicLinkDomain = settings.DynamicLinkDomain;
#pragma warning restore CS0618
this.LinkDomain = settings.LinkDomain;
this.IosBundleId = settings.IosBundleId;
this.AndroidPackageName = settings.AndroidPackageName;
this.AndroidMinimumVersion = settings.AndroidMinimumVersion;
Expand Down Expand Up @@ -70,6 +73,9 @@ private EmailActionLinkRequest(string type, string email, ActionCodeSettings set
[JsonProperty("dynamicLinkDomain")]
internal string DynamicLinkDomain { get; }

[JsonProperty("linkDomain")]
internal string LinkDomain { get; }

[JsonProperty("iOSBundleId")]
internal string IosBundleId { get; }

Expand Down Expand Up @@ -125,6 +131,11 @@ private void ValidateSettings()
throw new ArgumentException("DynamicLinkDomain must not be empty");
}

if (this.LinkDomain == string.Empty)
{
throw new ArgumentException("LinkDomain must not be empty");
}

if (this.IosBundleId == string.Empty)
{
throw new ArgumentException("IosBundleId must not be empty");
Expand Down