Skip to content

Commit 7e12e06

Browse files
authored
Merge cce083c into 36be62a
2 parents 36be62a + cce083c commit 7e12e06

File tree

262 files changed

+47338
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+47338
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
extends: '../../config/.eslintrc.js',
20+
parserOptions: {
21+
project: 'tsconfig.json',
22+
// to make vscode-eslint work with monorepo
23+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
24+
tsconfigRootDir: __dirname
25+
}
26+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/auth-compat-exp
2+
3+
This is a compatability layer to for the Firebase Authentication SDK
4+
5+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**

packages-exp/auth-compat-exp/demo/.eslintignore

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
extends: '../../../config/.eslintrc.js',
20+
parserOptions: {
21+
project: 'tsconfig.json',
22+
// to make vscode-eslint work with monorepo
23+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
24+
tsconfigRootDir: __dirname
25+
},
26+
rules: {
27+
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }]
28+
}
29+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/config.js
2+
.firebaserc
3+
public/config.js
4+
public/service-worker.*
5+
public/web-worker.*
6+
public/index.*
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Firebase-Auth for web - Auth Demo (Auth Compatibility Layer)
2+
3+
## Prerequisite
4+
5+
You need to have created a Firebase Project in the
6+
[Firebase Console](https://firebase.google.com/console/) as well as configured a web app.
7+
8+
## Installation
9+
Make sure you run `yarn` to install all dependencies in the root directory.
10+
11+
Enable the Auth providers you would like to offer your users in the console, under
12+
Auth > Sign-in methods.
13+
14+
Run:
15+
16+
```bash
17+
git clone https://github.com/firebase/firebase-js-sdk.git
18+
cd firebase-js-sdk/packages-exp/auth-compat-exp/demo
19+
```
20+
21+
This will clone the repository in the current directory.
22+
23+
If you want to be able to deploy the demo app to one of your own Firebase Hosting instance,
24+
configure it using the following command:
25+
26+
```bash
27+
firebase use --add
28+
```
29+
30+
Select the project you have created in the prerequisite, and type in `default` or
31+
any other name as the alias to use for this project.
32+
33+
Copy `public/sample-config.js` to `public/config.js`:
34+
35+
```bash
36+
cp public/sample-config.js public/config.js
37+
```
38+
39+
Then copy and paste the Web snippet config found in the console (either by clicking "Add Firebase to
40+
your web app" button in your Project overview, or clicking the "Web setup" button in the Auth page)
41+
in the `config.js` file.
42+
43+
In the `functions` folder you'll need to install the admin SDK:
44+
45+
```bash
46+
cd functions
47+
yarn install
48+
```
49+
50+
## Deploy
51+
52+
Before deploying, you may need to build the auth-exp package:
53+
```bash
54+
yarn build:deps
55+
```
56+
57+
You'll also need to build a fully resolved firebase-app.js and firebase-auth.js from auth-compat-exp:
58+
59+
```bash
60+
yarn build
61+
```
62+
63+
This can take some time, and you only need to do it if you've modified the auth-exp or auth-compta-exp packages.
64+
65+
To run the app locally, simply issue the following command in the `auth-compat-exp/demo` directory:
66+
67+
```bash
68+
yarn run demo
69+
```
70+
71+
This will compile all the files needed to run Firebase Auth, and start a Firebase server locally at
72+
[http://localhost:5000](http://localhost:5000).
73+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"rules": {
3+
".read": "auth != null",
4+
".write": "auth != null",
5+
"users": {
6+
"$user_id": {
7+
".read": "$user_id === auth.uid",
8+
".write": "$user_id === auth.uid"
9+
}
10+
}
11+
}
12+
}
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"database": {
3+
"rules": "database.rules.json"
4+
},
5+
"hosting": {
6+
"public": "public",
7+
"rewrites": [
8+
{
9+
"source": "/checkIfAuthenticated",
10+
"function": "checkIfAuthenticated"
11+
}
12+
]
13+
}
14+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @fileoverview Defines the HTTP endpoints hosted via firebase functions which
20+
* are used to test service worker functionality for Firebase Auth via demo
21+
* app.
22+
*/
23+
24+
const functions = require('firebase-functions');
25+
const admin = require('firebase-admin');
26+
27+
admin.initializeApp(functions.config().firebase);
28+
29+
exports.checkIfAuthenticated = functions.https.onRequest((req, res) => {
30+
const idToken = req.get('x-id-token');
31+
res.setHeader('Content-Type', 'application/json');
32+
if (idToken) {
33+
admin
34+
.auth()
35+
.verifyIdToken(idToken)
36+
.then(decodedIdToken => {
37+
res.status(200).send(JSON.stringify({ uid: decodedIdToken.sub }));
38+
})
39+
.catch(error => {
40+
res.status(400).send(JSON.stringify({ error: error.code }));
41+
});
42+
} else {
43+
res.status(403).send(JSON.stringify({ error: 'Unauthorized access' }));
44+
}
45+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "functions",
3+
"description": "Cloud Functions for Firebase",
4+
"scripts": {
5+
"serve": "firebase serve --only functions",
6+
"shell": "firebase experimental:functions:shell",
7+
"start": "yarn shell",
8+
"deploy": "firebase deploy --only functions",
9+
"logs": "firebase functions:log"
10+
},
11+
"dependencies": {
12+
"firebase-admin": "8.11.0",
13+
"firebase-functions": "3.6.1"
14+
},
15+
"private": true
16+
}

0 commit comments

Comments
 (0)