Skip to content

Commit be2aa60

Browse files
committed
Add support for app check in authui widget
1 parent 5ff6fde commit be2aa60

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* @fileoverview Firebase App Check API.
19+
* @externs
20+
*/
21+
22+
/**
23+
* @namespace
24+
* @param {!firebase.app.App=} app
25+
*
26+
* @return {!firebase.appCheck.AppCheck}
27+
*/
28+
firebase.appCheck = function (app) {};
29+
30+
/**
31+
* @interface
32+
*/
33+
firebase.appCheck.AppCheck = function () {};
34+
35+
/**
36+
* @param {firebase.appCheck.ReCaptchaEnterpriseProvider} provider
37+
* @param {boolean} refresh
38+
*/
39+
firebase.appCheck.AppCheck.prototype.activate = function (provider, refresh) {};
40+
41+
/**
42+
* @constructor
43+
*/
44+
firebase.appCheck.ReCaptchaEnterpriseProvider = function (appCheckToken) {};

gulpfile.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const MDL_COMPONENTS = [
6666
const ESM_DEPS = [
6767
'import firebase from \'firebase/compat/app\'',
6868
'import \'firebase/compat/auth\'',
69+
'import \'firebase/compat/app-check\'',
6970
'import dialogPolyfill from \'dialog-polyfill\'',
7071
].concat(MDL_COMPONENTS.map(component => `import \'material-design-lite/src/${component}\'`));
7172

@@ -83,11 +84,11 @@ const ESM_EXPORT = 'var auth = firebaseui.auth;' +
8384

8485
// Adds the cjs module requirement and exports firebaseui.
8586
const NPM_MODULE_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
86-
'var firebase=require(\'firebase/compat/app\');require(\'firebase/compat/auth\');' +
87+
'var firebase=require(\'firebase/compat/app\');require(\'firebase/compat/auth\');require(\'firebase/compat/app-check\');' +
8788
DEFAULT_IMPORT_FIX + '%output%' + DIALOG_POLYFILL +
8889
'module.exports=firebaseui;' :
8990
'(function() { var firebase=require(\'firebase/compat/app\');' +
90-
'require(\'firebase/compat/auth\');' + DEFAULT_IMPORT_FIX + '%output% ' +
91+
'require(\'firebase/compat/auth\');' + 'require(\'firebase/compat/app-check\');' + DEFAULT_IMPORT_FIX + '%output% ' +
9192
DIALOG_POLYFILL + '})();' + 'module.exports=firebaseui;';
9293

9394
// Adds the module requirement and exports firebaseui.
@@ -223,6 +224,7 @@ function buildFirebaseUiJs(locale) {
223224
define: `goog.LOCALE='${locale}'`,
224225
externs: [
225226
'firebase-externs/firebase-app-externs.js',
227+
'firebase-externs/firebase-app-check-externs.js',
226228
'firebase-externs/firebase-auth-externs.js',
227229
'firebase-externs/firebase-client-auth-externs.js'
228230
],

javascript/widgets/authui.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ goog.requireType('firebaseui.auth.ui.page.Base');
9999
/**
100100
* @param {!firebase.auth.Auth} auth The Firebase Auth instance.
101101
* @param {string=} opt_appId The optional app id.
102+
* @param {string=} appCheckToken The optional app id.
102103
* @constructor @struct
103104
*/
104-
firebaseui.auth.AuthUI = function(auth, opt_appId) {
105+
firebaseui.auth.AuthUI = function(auth, opt_appId, appCheckToken) {
105106
/** @private {boolean} Whether the current instance is deleted. */
106107
this.deleted_ = false;
107108
// Check if an instance with the same key exists. If so, throw an error,
@@ -125,9 +126,17 @@ firebaseui.auth.AuthUI = function(auth, opt_appId) {
125126
// Log FirebaseUI on external Auth instance.
126127
firebaseui.auth.AuthUI.logFirebaseUI_(this.auth_);
127128
var tempApp = firebase.initializeApp({
128-
'apiKey': auth['app']['options']['apiKey'],
129-
'authDomain': auth['app']['options']['authDomain']
129+
...auth['app']['options']
130130
}, auth['app']['name'] + firebaseui.auth.AuthUI.TEMP_APP_NAME_SUFFIX_);
131+
if (appCheckToken) {
132+
const appCheck = firebase.appCheck(tempApp);
133+
appCheck.activate(
134+
new firebase.appCheck.ReCaptchaEnterpriseProvider(
135+
appCheckToken
136+
),
137+
true // Set to true to allow auto-refresh.
138+
);
139+
}
131140
/**
132141
* @private {!firebase.auth.Auth} The temporary internal Firebase Auth
133142
* instance.

0 commit comments

Comments
 (0)