Skip to content

Added ability to custom FDL domain #1382

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

Merged
merged 1 commit into from
Nov 26, 2018
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
1 change: 1 addition & 0 deletions packages/auth-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type ActionCodeSettings = {
handleCodeInApp?: boolean;
iOS?: { bundleId: string };
url: string;
dynamicLinkDomain?: string;
};

export type AdditionalUserInfo = {
Expand Down
23 changes: 21 additions & 2 deletions packages/auth/src/actioncodesettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fireauth.ActionCodeSettings.prototype.initialize_ = function(settingsObj) {
(typeof continueUrl === 'string' && !continueUrl.length)) {
throw new fireauth.AuthError(fireauth.authenum.Error.INVALID_CONTINUE_URI);
}
/** @private {string} The continue URL. */
/** @const @private {string} The continue URL. */
this.continueUrl_ = /** @type {string} */ (continueUrl);

// Validate Android parameters.
Expand Down Expand Up @@ -140,8 +140,23 @@ fireauth.ActionCodeSettings.prototype.initialize_ = function(settingsObj) {
fireauth.ActionCodeSettings.RawField.HANDLE_CODE_IN_APP +
' property must be a boolean when specified.');
}
/** @private {boolean} Whether the code can be handled in app. */
/** @const @private {boolean} Whether the code can be handled in app. */
this.canHandleCodeInApp_ = !!canHandleCodeInApp;

// Validate dynamicLinkDomain.
var dynamicLinkDomain = settingsObj[
fireauth.ActionCodeSettings.RawField.DYNAMIC_LINK_DOMAIN];
if (typeof dynamicLinkDomain !== 'undefined' &&
(typeof dynamicLinkDomain !== 'string' ||
(typeof dynamicLinkDomain === 'string' &&
!dynamicLinkDomain.length))) {
throw new fireauth.AuthError(
fireauth.authenum.Error.ARGUMENT_ERROR,
fireauth.ActionCodeSettings.RawField.DYNAMIC_LINK_DOMAIN +
' property must be a non empty string when specified.');
}
/** @const @private {?string} The FDL domain. */
this.dynamicLinkDomain_ = dynamicLinkDomain || null;
};


Expand All @@ -155,6 +170,7 @@ fireauth.ActionCodeSettings.RequestField = {
ANDROID_PACKAGE_NAME: 'androidPackageName',
CAN_HANDLE_CODE_IN_APP: 'canHandleCodeInApp',
CONTINUE_URL: 'continueUrl',
DYNAMIC_LINK_DOMAIN: 'dynamicLinkDomain',
IOS_BUNDLE_ID: 'iOSBundleId'
};

Expand All @@ -165,6 +181,7 @@ fireauth.ActionCodeSettings.RequestField = {
*/
fireauth.ActionCodeSettings.RawField = {
ANDROID: 'android',
DYNAMIC_LINK_DOMAIN: 'dynamicLinkDomain',
HANDLE_CODE_IN_APP: 'handleCodeInApp',
IOS: 'iOS',
URL: 'url'
Expand Down Expand Up @@ -212,6 +229,8 @@ fireauth.ActionCodeSettings.prototype.buildRequest = function() {
this.installApp_;
}
request[fireauth.ActionCodeSettings.RequestField.IOS_BUNDLE_ID] = this.ibi_;
request[fireauth.ActionCodeSettings.RequestField.DYNAMIC_LINK_DOMAIN] =
this.dynamicLinkDomain_;
// Remove null fields.
for (var key in request) {
if (request[key] === null) {
Expand Down
5 changes: 5 additions & 0 deletions packages/auth/src/error_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ fireauth.authenum.Error = {
INVALID_CONTINUE_URI: 'invalid-continue-uri',
INVALID_CORDOVA_CONFIGURATION: 'invalid-cordova-configuration',
INVALID_CUSTOM_TOKEN: 'invalid-custom-token',
INVALID_DYNAMIC_LINK_DOMAIN: 'invalid-dynamic-link-domain',
INVALID_EMAIL: 'invalid-email',
INVALID_IDP_RESPONSE: 'invalid-credential',
INVALID_MESSAGE_PAYLOAD: 'invalid-message-payload',
Expand Down Expand Up @@ -262,6 +263,10 @@ fireauth.AuthError.MESSAGES_[
'cordova-plugin-customurlscheme.';
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_CUSTOM_TOKEN] =
'The custom token format is incorrect. Please check the documentation.';
fireauth.AuthError.MESSAGES_[
fireauth.authenum.Error.INVALID_DYNAMIC_LINK_DOMAIN] = 'The provided ' +
'dynamic link domain is not configured or authorized for the current ' +
'project.';
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_EMAIL] =
'The email address is badly formatted.';
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_API_KEY] =
Expand Down
3 changes: 3 additions & 0 deletions packages/auth/src/rpchandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ fireauth.RpcHandler.ServerError = {
INVALID_CODE: 'INVALID_CODE',
INVALID_CONTINUE_URI: 'INVALID_CONTINUE_URI',
INVALID_CUSTOM_TOKEN: 'INVALID_CUSTOM_TOKEN',
INVALID_DYNAMIC_LINK_DOMAIN: 'INVALID_DYNAMIC_LINK_DOMAIN',
INVALID_EMAIL: 'INVALID_EMAIL',
INVALID_ID_TOKEN: 'INVALID_ID_TOKEN',
INVALID_IDP_RESPONSE: 'INVALID_IDP_RESPONSE',
Expand Down Expand Up @@ -2321,6 +2322,8 @@ fireauth.RpcHandler.getDeveloperError_ =
fireauth.authenum.Error.MISSING_IOS_BUNDLE_ID;
errorMap[fireauth.RpcHandler.ServerError.UNAUTHORIZED_DOMAIN] =
fireauth.authenum.Error.UNAUTHORIZED_DOMAIN;
errorMap[fireauth.RpcHandler.ServerError.INVALID_DYNAMIC_LINK_DOMAIN] =
fireauth.authenum.Error.INVALID_DYNAMIC_LINK_DOMAIN;

// getProjectConfig errors when clientId is passed.
errorMap[fireauth.RpcHandler.ServerError.INVALID_OAUTH_CLIENT_ID] =
Expand Down
89 changes: 87 additions & 2 deletions packages/auth/test/actioncodesettings_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ function testActionCodeSettings_success_allParameters() {
'installApp': true,
'minimumVersion': '12'
},
'handleCodeInApp': true
'handleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
};
var expectedRequest = {
'continueUrl': 'https://www.example.com/?state=abc',
'iOSBundleId': 'com.example.ios',
'androidPackageName': 'com.example.android',
'androidInstallApp': true,
'androidMinimumVersion': '12',
'canHandleCodeInApp': true
'canHandleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
};
var actionCodeSettings = new fireauth.ActionCodeSettings(settings);
assertObjectEquals(expectedRequest, actionCodeSettings.buildRequest());
Expand All @@ -82,6 +84,24 @@ function testActionCodeSettings_success_partialParameters() {
}


function testActionCodeSettings_success_partialParameters_fdlDomain() {
var settings = {
'url': 'https://www.example.com/?state=abc',
// Will be ignored.
'iOS': {},
'android': {},
'dynamicLinkDomain': 'example.page.link'
};
var expectedRequest = {
'continueUrl': 'https://www.example.com/?state=abc',
'canHandleCodeInApp': false,
'dynamicLinkDomain': 'example.page.link'
};
var actionCodeSettings = new fireauth.ActionCodeSettings(settings);
assertObjectEquals(expectedRequest, actionCodeSettings.buildRequest());
}


function testActionCodeSettings_success_partialParameters_android() {
var settings = {
'url': 'https://www.example.com/?state=abc',
Expand All @@ -100,6 +120,26 @@ function testActionCodeSettings_success_partialParameters_android() {
}


function testActionCodeSettings_success_partialParameters_android_fdlDomain() {
var settings = {
'url': 'https://www.example.com/?state=abc',
'android': {
'packageName': 'com.example.android'
},
'dynamicLinkDomain': 'example.page.link'
};
var expectedRequest = {
'continueUrl': 'https://www.example.com/?state=abc',
'androidPackageName': 'com.example.android',
'androidInstallApp': false,
'canHandleCodeInApp': false,
'dynamicLinkDomain': 'example.page.link'
};
var actionCodeSettings = new fireauth.ActionCodeSettings(settings);
assertObjectEquals(expectedRequest, actionCodeSettings.buildRequest());
}


function testActionCodeSettings_success_partialParameters_ios() {
var settings = {
'url': 'https://www.example.com/?state=abc',
Expand All @@ -117,6 +157,25 @@ function testActionCodeSettings_success_partialParameters_ios() {
}


function testActionCodeSettings_success_partialParameters_ios_fdlDomain() {
var settings = {
'url': 'https://www.example.com/?state=abc',
'iOS': {
'bundleId': 'com.example.ios'
},
'dynamicLinkDomain': 'example.page.link'
};
var expectedRequest = {
'continueUrl': 'https://www.example.com/?state=abc',
'iOSBundleId': 'com.example.ios',
'canHandleCodeInApp': false,
'dynamicLinkDomain': 'example.page.link'
};
var actionCodeSettings = new fireauth.ActionCodeSettings(settings);
assertObjectEquals(expectedRequest, actionCodeSettings.buildRequest());
}


function testActionCodeSettings_error_continueUrl() {
// Missing continue URL.
assertActionCodeSettingsErrorThrown(
Expand Down Expand Up @@ -258,3 +317,29 @@ function testActionCodeSettings_error_ios() {
},
'auth/argument-error');
}


function testActionCodeSettings_error_dynamicLinkDomain() {
// Invalid dynamic link domain.
assertActionCodeSettingsErrorThrown(
{
'url': 'https://www.example.com/?state=abc',
'dynamicLinkDomain': ['example.page.link']

},
'auth/argument-error');
// Dynamic link domain set to empty string.
assertActionCodeSettingsErrorThrown(
{
'url': 'https://www.example.com/?state=abc',
'dynamicLinkDomain': ''
},
'auth/argument-error');
// Dynamic link domain set to null.
assertActionCodeSettingsErrorThrown(
{
'url': 'https://www.example.com/?state=abc',
'dynamicLinkDomain': null
},
'auth/argument-error');
}
3 changes: 2 additions & 1 deletion packages/auth/test/auth_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ var actionCodeSettings = {
'installApp': true,
'minimumVersion': '12'
},
'handleCodeInApp': true
'handleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
};
var mockLocalStorage;
var mockSessionStorage;
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/test/authuser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ var actionCodeSettings = {
'installApp': true,
'minimumVersion': '12'
},
'handleCodeInApp': true
'handleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
};
var lastLoginAt = '1506050282000';
var createdAt = '1506044998000';
Expand Down
24 changes: 18 additions & 6 deletions packages/auth/test/rpchandler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3660,7 +3660,8 @@ function testSendSignInLinkToEmail_success_actionCodeSettings() {
'androidPackageName': 'com.example.android',
'androidInstallApp': true,
'androidMinimumVersion': '12',
'canHandleCodeInApp': true
'canHandleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
};
var expectedResponse = {'email': userEmail};
asyncTestCase.waitForSignals(1);
Expand All @@ -3676,7 +3677,8 @@ function testSendSignInLinkToEmail_success_actionCodeSettings() {
'androidPackageName': 'com.example.android',
'androidInstallApp': true,
'androidMinimumVersion': '12',
'canHandleCodeInApp': true
'canHandleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
}),
fireauth.RpcHandler.DEFAULT_FIREBASE_HEADERS_,
delay,
Expand Down Expand Up @@ -3825,6 +3827,8 @@ function testSendSignInLinkToEmail_serverCaughtError() {
fireauth.authenum.Error.MISSING_IOS_BUNDLE_ID;
errorMap[fireauth.RpcHandler.ServerError.UNAUTHORIZED_DOMAIN] =
fireauth.authenum.Error.UNAUTHORIZED_DOMAIN;
errorMap[fireauth.RpcHandler.ServerError.INVALID_DYNAMIC_LINK_DOMAIN] =
fireauth.authenum.Error.INVALID_DYNAMIC_LINK_DOMAIN;

assertServerErrorsAreHandled(function() {
return rpcHandler.sendSignInLinkToEmail(userEmail, {});
Expand All @@ -3843,7 +3847,8 @@ function testSendPasswordResetEmail_success_actionCodeSettings() {
'androidPackageName': 'com.example.android',
'androidInstallApp': true,
'androidMinimumVersion': '12',
'canHandleCodeInApp': true
'canHandleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
};
var expectedResponse = {
'email': userEmail
Expand All @@ -3861,7 +3866,8 @@ function testSendPasswordResetEmail_success_actionCodeSettings() {
'androidPackageName': 'com.example.android',
'androidInstallApp': true,
'androidMinimumVersion': '12',
'canHandleCodeInApp': true
'canHandleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
}),
fireauth.RpcHandler.DEFAULT_FIREBASE_HEADERS_,
delay,
Expand Down Expand Up @@ -4012,6 +4018,8 @@ function testSendPasswordResetEmail_caughtServerError() {
fireauth.authenum.Error.MISSING_IOS_BUNDLE_ID;
errorMap[fireauth.RpcHandler.ServerError.UNAUTHORIZED_DOMAIN] =
fireauth.authenum.Error.UNAUTHORIZED_DOMAIN;
errorMap[fireauth.RpcHandler.ServerError.INVALID_DYNAMIC_LINK_DOMAIN] =
fireauth.authenum.Error.INVALID_DYNAMIC_LINK_DOMAIN;

assertServerErrorsAreHandled(function() {
return rpcHandler.sendPasswordResetEmail(userEmail, {});
Expand All @@ -4034,7 +4042,8 @@ function testSendEmailVerification_success_actionCodeSettings() {
'androidPackageName': 'com.example.android',
'androidInstallApp': true,
'androidMinimumVersion': '12',
'canHandleCodeInApp': true
'canHandleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
};
asyncTestCase.waitForSignals(1);
assertSendXhrAndRunCallback(
Expand All @@ -4049,7 +4058,8 @@ function testSendEmailVerification_success_actionCodeSettings() {
'androidPackageName': 'com.example.android',
'androidInstallApp': true,
'androidMinimumVersion': '12',
'canHandleCodeInApp': true
'canHandleCodeInApp': true,
'dynamicLinkDomain': 'example.page.link'
}),
fireauth.RpcHandler.DEFAULT_FIREBASE_HEADERS_,
delay,
Expand Down Expand Up @@ -4176,6 +4186,8 @@ function testSendEmailVerification_caughtServerError() {
fireauth.authenum.Error.MISSING_IOS_BUNDLE_ID;
errorMap[fireauth.RpcHandler.ServerError.UNAUTHORIZED_DOMAIN] =
fireauth.authenum.Error.UNAUTHORIZED_DOMAIN;
errorMap[fireauth.RpcHandler.ServerError.INVALID_DYNAMIC_LINK_DOMAIN] =
fireauth.authenum.Error.INVALID_DYNAMIC_LINK_DOMAIN;

assertServerErrorsAreHandled(function() {
return rpcHandler.sendEmailVerification(idToken, {});
Expand Down
1 change: 1 addition & 0 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ declare namespace firebase.auth {
handleCodeInApp?: boolean;
iOS?: { bundleId: string };
url: string;
dynamicLinkDomain?: string;
};

type AdditionalUserInfo = {
Expand Down