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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Adds Emulator support to Auth UI. Fixes
https://github.com/firebase/firebaseui-web/issues/778
24 changes: 22 additions & 2 deletions javascript/testing/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ goog.module('firebaseui.auth.testing.FakeAuthClient');
goog.module.declareLegacyNamespace();
goog.setTestOnly();

var MockHelper = goog.require('firebaseui.auth.testing.MockHelper');
var array = goog.require('goog.array');
const MockHelper = goog.require('firebaseui.auth.testing.MockHelper');
const Uri = goog.require('goog.Uri');
const array = goog.require('goog.array');


/**
* Fake Auth API client class.
Expand All @@ -37,6 +39,7 @@ class FakeAuthClient extends MockHelper {
this.user_ = {};
this['app'] = app;
this['currentUser'] = null;
this['emulatorConfig'] = null;
var asyncMethods = {};
// Populate auth async methods.
for (var key in FakeAuthClient.AuthAsyncMethod) {
Expand Down Expand Up @@ -66,6 +69,23 @@ class FakeAuthClient extends MockHelper {
};
}

/**
* Mock useEmulator() function from main SDK.
* @param {string} url The url to talk to the emulator with.
* @param {?Object} options Options for emulator config.
*/
useEmulator(url, options) {
const uri = Uri.parse(url);
this['emulatorConfig'] = {
'protocol': uri.getScheme(),
'host': uri.getDomain(),
'port': uri.getPort(),
'options': {
'disableWarnings': options ? options.disableWarnings : false,
},
};
}

/**
* Asserts the expected list of frameworks IDs are logged.
* @param {!Array<string>} expectedFrameworks The expected list of frameworks
Expand Down
6 changes: 6 additions & 0 deletions javascript/widgets/authui.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ firebaseui.auth.AuthUI = function(auth, opt_appId) {
* instance.
*/
this.tempAuth_ = tempApp.auth();
const emulatorConfig = auth.emulatorConfig;
if (emulatorConfig) {
const {protocol, host, port, options} = emulatorConfig;
const portString = port === null ? '' : ':' + port;
this.tempAuth_.useEmulator(`${protocol}://${host}${portString}`, options);
}
// Log FirebaseUI on internal Auth instance.
firebaseui.auth.AuthUI.logFirebaseUI_(this.tempAuth_);
// Change persistence to session to avoid the risk of dangling auth states in
Expand Down
42 changes: 42 additions & 0 deletions javascript/widgets/authui_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ function testGetExternalAuth() {
assertEquals('testapp2-firebaseui-temp', app2.getAuth().app.name);
}


function testTempAuth_sessionPersistence() {
createAndInstallTestInstances();
// Initialize app.
Expand All @@ -528,6 +529,47 @@ function testTempAuth_sessionPersistence() {
}


function testTempAuth_emulatorConfig() {
createAndInstallTestInstances();
// Initialize app.
testAuth.install();
testAuth.useEmulator('http://localhost:1234');
app = new firebaseui.auth.AuthUI(testAuth, 'id0');
// Confirm correct name used for temp instance.
assertEquals('testapp1-firebaseui-temp', app1.getAuth().app.name);
// Confirm emulator config properly set on internal instance.
assertObjectEquals({
protocol: 'http',
host: 'localhost',
port: 1234,
options: {
disableWarnings: false,
}
}, app.getAuth().emulatorConfig);
}


function testTempAuth_emulatorConfig_handlesIPV6Hosts() {
createAndInstallTestInstances();
// Initialize app.
testAuth.install();
testAuth.useEmulator(
'http://[0:0:0:0:0:0:0:0]:1234', {disableWarnings: true});
app = new firebaseui.auth.AuthUI(testAuth, 'id0');
// Confirm correct name used for temp instance.
assertEquals('testapp1-firebaseui-temp', app1.getAuth().app.name);
// Confirm emulator config hasn't double-quoted IPv6 address.
assertObjectEquals({
protocol: 'http',
host: '[0:0:0:0:0:0:0:0]',
port: 1234,
options: {
disableWarnings: true,
}
}, app.getAuth().emulatorConfig);
}


function testAppId() {
createAndInstallTestInstances();
// Confirm correct app id stored for each app.
Expand Down
Loading