-
Notifications
You must be signed in to change notification settings - Fork 945
Copy demo code over to auth-compat-layer, fix our build scripts #3563
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module.exports = { | ||
extends: '../../../config/.eslintrc.js', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
// to make vscode-eslint work with monorepo | ||
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250 | ||
tsconfigRootDir: __dirname | ||
}, | ||
rules: { | ||
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }] | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"avolkovi-auth": "avolkovi-auth" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
src/config.js | ||
.firebaserc | ||
public/config.js | ||
public/service-worker.* | ||
public/web-worker.* | ||
public/index.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Firebase-Auth for web - Auth Demo (Auth Compatibility Layer) | ||
|
||
## Prerequisite | ||
|
||
You need to have created a Firebase Project in the | ||
[Firebase Console](https://firebase.google.com/console/) as well as configured a web app. | ||
|
||
## Installation | ||
Make sure you run `yarn` to install all dependencies in the root directory. | ||
|
||
Enable the Auth providers you would like to offer your users in the console, under | ||
Auth > Sign-in methods. | ||
|
||
Run: | ||
|
||
```bash | ||
git clone https://github.com/firebase/firebase-js-sdk.git | ||
cd firebase-js-sdk/packages-exp/auth-compat-exp/demo | ||
``` | ||
|
||
This will clone the repository in the current directory. | ||
|
||
If you want to be able to deploy the demo app to one of your own Firebase Hosting instance, | ||
configure it using the following command: | ||
|
||
```bash | ||
firebase use --add | ||
``` | ||
|
||
Select the project you have created in the prerequisite, and type in `default` or | ||
any other name as the alias to use for this project. | ||
|
||
Copy `public/sample-config.js` to `public/config.js`: | ||
|
||
```bash | ||
cp public/sample-config.js public/config.js | ||
``` | ||
|
||
Then copy and paste the Web snippet config found in the console (either by clicking "Add Firebase to | ||
your web app" button in your Project overview, or clicking the "Web setup" button in the Auth page) | ||
in the `config.js` file. | ||
|
||
In the `functions` folder you'll need to install the admin SDK: | ||
|
||
```bash | ||
cd functions | ||
yarn install | ||
``` | ||
|
||
## Deploy | ||
|
||
Before deploying, you may need to build the auth-exp package: | ||
```bash | ||
yarn build:deps | ||
``` | ||
|
||
You'll also need to build a fully resolved firebase-app.js and firebase-auth.js from auth-compat-exp: | ||
|
||
```bash | ||
yarn build | ||
``` | ||
|
||
This can take some time, and you only need to do it if you've modified the auth-exp or auth-compta-exp packages. | ||
|
||
To run the app locally, simply issue the following command in the `auth-compat-exp/demo` directory: | ||
|
||
```bash | ||
yarn run demo | ||
``` | ||
|
||
This will compile all the files needed to run Firebase Auth, and start a Firebase server locally at | ||
[http://localhost:5000](http://localhost:5000). | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"rules": { | ||
".read": "auth != null", | ||
".write": "auth != null", | ||
"users": { | ||
"$user_id": { | ||
".read": "$user_id === auth.uid", | ||
".write": "$user_id === auth.uid" | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"database": { | ||
"rules": "database.rules.json" | ||
}, | ||
"hosting": { | ||
"public": "public", | ||
"rewrites": [ | ||
{ | ||
"source": "/checkIfAuthenticated", | ||
"function": "checkIfAuthenticated" | ||
} | ||
] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @license | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Defines the HTTP endpoints hosted via firebase functions which | ||
* are used to test service worker functionality for Firebase Auth via demo | ||
* app. | ||
*/ | ||
|
||
const functions = require('firebase-functions'); | ||
const admin = require('firebase-admin'); | ||
|
||
admin.initializeApp(functions.config().firebase); | ||
|
||
exports.checkIfAuthenticated = functions.https.onRequest((req, res) => { | ||
const idToken = req.get('x-id-token'); | ||
res.setHeader('Content-Type', 'application/json'); | ||
if (idToken) { | ||
admin | ||
.auth() | ||
.verifyIdToken(idToken) | ||
.then(decodedIdToken => { | ||
res.status(200).send(JSON.stringify({ uid: decodedIdToken.sub })); | ||
}) | ||
.catch(error => { | ||
res.status(400).send(JSON.stringify({ error: error.code })); | ||
}); | ||
} else { | ||
res.status(403).send(JSON.stringify({ error: 'Unauthorized access' })); | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "functions", | ||
"description": "Cloud Functions for Firebase", | ||
"scripts": { | ||
"serve": "firebase serve --only functions", | ||
"shell": "firebase experimental:functions:shell", | ||
"start": "yarn shell", | ||
"deploy": "firebase deploy --only functions", | ||
"logs": "firebase functions:log" | ||
}, | ||
"dependencies": { | ||
"firebase-admin": "8.11.0", | ||
"firebase-functions": "3.6.1" | ||
}, | ||
"private": true | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.