Skip to content

Commit e406aca

Browse files
feat(auth): Firebase Auth add link domain to actionCodeSetting (#1115)
* add link domain to actionCodeSetting * fix: Correct deprecation tag * fix(auth): Fix doc string and use correct error message --------- Co-authored-by: jonathanedey <jedey@google.com> Co-authored-by: Jonathan Edey <145066863+jonathanedey@users.noreply.github.com>
1 parent 212ecea commit e406aca

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/main/java/com/google/firebase/auth/ActionCodeSettings.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ private ActionCodeSettings(Builder builder) {
5151
if (!Strings.isNullOrEmpty(builder.dynamicLinkDomain)) {
5252
properties.put("dynamicLinkDomain", builder.dynamicLinkDomain);
5353
}
54+
if (!Strings.isNullOrEmpty(builder.linkDomain)) {
55+
properties.put("linkDomain", builder.linkDomain);
56+
}
5457
if (!Strings.isNullOrEmpty(builder.iosBundleId)) {
5558
properties.put("iOSBundleId", builder.iosBundleId);
5659
}
@@ -84,6 +87,7 @@ public static final class Builder {
8487
private String url;
8588
private boolean handleCodeInApp;
8689
private String dynamicLinkDomain;
90+
private String linkDomain;
8791
private String iosBundleId;
8892
private String androidPackageName;
8993
private String androidMinimumVersion;
@@ -135,12 +139,28 @@ public Builder setHandleCodeInApp(boolean handleCodeInApp) {
135139
*
136140
* @param dynamicLinkDomain Firebase Dynamic Link domain string.
137141
* @return This builder.
142+
* @deprecated Use {@link #setLinkDomain(String)} instead.
138143
*/
144+
@Deprecated
139145
public Builder setDynamicLinkDomain(String dynamicLinkDomain) {
140146
this.dynamicLinkDomain = dynamicLinkDomain;
141147
return this;
142148
}
143149

150+
/**
151+
* Sets the link domain to use for the current link if it is to be opened using
152+
* {@code handleCodeInApp}, as multiple link domains can be configured per project. This
153+
* setting provides the ability to explicitly choose one. If none is provided, the default
154+
* Firebase Hosting domain will be used.
155+
*
156+
* @param linkDomain Link domain string.
157+
* @return This builder.
158+
*/
159+
public Builder setLinkDomain(String linkDomain) {
160+
this.linkDomain = linkDomain;
161+
return this;
162+
}
163+
144164
/**
145165
* Sets the bundle ID of the iOS app where the link should be handled if the
146166
* application is already installed on the device.

src/main/java/com/google/firebase/auth/AuthErrorCode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public enum AuthErrorCode {
5858
*/
5959
INVALID_DYNAMIC_LINK_DOMAIN,
6060

61+
/**
62+
* The provided hosting link domain is not configured or authorized for the current project.
63+
*/
64+
INVALID_HOSTING_LINK_DOMAIN,
65+
6166
/**
6267
* The specified ID token is invalid.
6368
*/

src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ final class AuthErrorHandler extends AbstractHttpErrorHandler<FirebaseAuthExcept
7373
"The provided dynamic link domain is not "
7474
+ "configured or authorized for the current project",
7575
AuthErrorCode.INVALID_DYNAMIC_LINK_DOMAIN))
76+
.put(
77+
"INVALID_HOSTING_LINK_DOMAIN",
78+
new AuthError(
79+
ErrorCode.INVALID_ARGUMENT,
80+
"The provided hosting link domain is not configured in Firebase Hosting or is "
81+
+ "not owned by the current project",
82+
AuthErrorCode.INVALID_HOSTING_LINK_DOMAIN))
7683
.put(
7784
"PHONE_NUMBER_EXISTS",
7885
new AuthError(

src/test/java/com/google/firebase/auth/ActionCodeSettingsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void testAllSettings() {
6868
.setUrl("https://example.com")
6969
.setHandleCodeInApp(true)
7070
.setDynamicLinkDomain("myapp.page.link")
71+
.setLinkDomain("myapp.custom.link")
7172
.setIosBundleId("com.example.ios")
7273
.setAndroidPackageName("com.example.android")
7374
.setAndroidMinimumVersion("6.0")
@@ -77,6 +78,7 @@ public void testAllSettings() {
7778
.put("continueUrl", "https://example.com")
7879
.put("canHandleCodeInApp", true)
7980
.put("dynamicLinkDomain", "myapp.page.link")
81+
.put("linkDomain", "myapp.custom.link")
8082
.put("iOSBundleId", "com.example.ios")
8183
.put("androidPackageName", "com.example.android")
8284
.put("androidMinimumVersion", "6.0")

0 commit comments

Comments
 (0)