Skip to content
This repository was archived by the owner on Mar 10, 2021. It is now read-only.

Commit deeec40

Browse files
committed
Implemented google-auth
1 parent bea8d78 commit deeec40

File tree

10 files changed

+230
-93
lines changed

10 files changed

+230
-93
lines changed

.DS_Store

0 Bytes
Binary file not shown.

manifest.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

public/manifest.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
2-
"name": "Footsteps",
2+
"name": "Footsteps by FnPlus",
33
"version": "1.0",
4-
"description": "and let others follow your footsteps",
4+
"description": "An open learning platform for commmunities. Build your own learning paths and let others follow your footsteps",
55
"manifest_version": 2,
66
"background": {
77
"scripts": [
88
"background-script.js"
9-
]
9+
],
10+
"persistent": false
1011
},
1112
"permissions": [
13+
"identity"
1214
],
1315
"content_scripts": [
1416
{
@@ -21,6 +23,15 @@
2123
"browser_action": {
2224
"default_icon": "icon.png",
2325
"default_title": "Footsteps",
24-
"default_popup": "popup.html"
25-
}
26-
}
26+
"default_popup": "credentials.html"
27+
},
28+
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlYYAiO9QEDcWW+LTz8SCyZ93mFALZ97gkgmWY36y6/dCtIzacLkFmYbZ/vgD9+TQgtmMgZsuHtGwp5dDMGbjMIa3yKEuy0YYeJ4aTpeQesjQL7/f7Jx1x8iXjVbj/GdFhuExOVSIANbWt+HD3+252D/0QVysDBmz9Zko1RMM4ptDfT1fQCo4Y/OllZbHo52KU+DieCkFKIvfGTy4j4rQn1RUGZ7JMTYj9hGCvzH0wPlRyMsFHDxeEIqQuQGDoahfoGFlI/KQpeBcI25Fr0Y2k1LE+JH5qUWpKcwBH4rJrdvjaepjGSg8Y5o/tunV9Oyx1+gLKLLIKqIQUNtPG+eViwIDAQAB",
29+
"oauth2": {
30+
"client_id": "1064007003546-9ti8pvpnv603kvjbia1a27ffirunqhge.apps.googleusercontent.com",
31+
"scopes": [
32+
"https://www.googleapis.com/auth/userinfo.email",
33+
"https://www.googleapis.com/auth/userinfo.profile"
34+
]
35+
},
36+
"content_security_policy":"script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'"
37+
}

src/auth/background.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<head>
3+
<meta charset=utf-8 />
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
6+
<title>Google Sign In</title>
7+
8+
<link rel="stylesheet" href="main.css">
9+
10+
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase.js"></script>
11+
<script src="../background.js"></script>
12+
</head>
13+
<body>
14+
15+
</body>
16+
</html>

src/auth/credentials.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<html>
2+
<head>
3+
<meta charset=utf-8 />
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<title>Google Sign In</title>
6+
7+
<link rel="stylesheet" href="main.css">
8+
9+
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase.js"></script>
10+
<script src="credentials.js"></script>
11+
</head>
12+
<body>
13+
<h3>Firebase Authentication</h3>
14+
15+
<div class="quickstart-user-details-container">
16+
<button id="quickstart-button">Sign-in with Google</button>
17+
<p>
18+
Firebase sign-in status: <span id="quickstart-sign-in-status">Unknown</span>
19+
<div>Firebase auth <code>currentUser</code> object value:</div>
20+
<pre><code id="quickstart-account-details">null</code></pre>
21+
</p>
22+
</div>
23+
</body>
24+
</html>

src/auth/credentials.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Initialize Firebase
2+
var config = {
3+
apiKey: 'AIzaSyCbBsA6NBf-Ko1iIQZLcIR2cpspWslwx5I',
4+
authDomain: "fnplus-rle-mvp.firebaseapp.com",
5+
projectId: "fnplus-rle-mvp",
6+
appId: "1:1064007003546:web:187ca42dbcf8a58d"
7+
};
8+
firebase.initializeApp(config);
9+
10+
/**
11+
* initApp handles setting up the Firebase context and registering
12+
* callbacks for the auth status.
13+
*
14+
* The core initialization is in firebase.App - this is the glue class
15+
* which stores configuration. We provide an app name here to allow
16+
* distinguishing multiple app instances.
17+
*
18+
* This method also registers a listener with firebase.auth().onAuthStateChanged.
19+
* This listener is called when the user is signed in or out, and that
20+
* is where we update the UI.
21+
*
22+
* When signed in, we also authenticate to the Firebase Realtime Database.
23+
*/
24+
function initApp() {
25+
// Listen for auth state changes.
26+
// [START authstatelistener]
27+
firebase.auth().onAuthStateChanged(function(user) {
28+
if (user) {
29+
// User is signed in.
30+
var displayName = user.displayName;
31+
var email = user.email;
32+
var emailVerified = user.emailVerified;
33+
var photoURL = user.photoURL;
34+
var isAnonymous = user.isAnonymous;
35+
var uid = user.uid;
36+
var providerData = user.providerData;
37+
// [START_EXCLUDE]
38+
document.getElementById('quickstart-button').textContent = 'Sign out';
39+
document.getElementById('quickstart-sign-in-status').textContent = 'Signed in';
40+
document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
41+
// [END_EXCLUDE]
42+
} else {
43+
// Let's try to get a Google auth token programmatically.
44+
// [START_EXCLUDE]
45+
document.getElementById('quickstart-button').textContent = 'Sign-in with Google';
46+
document.getElementById('quickstart-sign-in-status').textContent = 'Signed out';
47+
document.getElementById('quickstart-account-details').textContent = 'null';
48+
// [END_EXCLUDE]
49+
}
50+
document.getElementById('quickstart-button').disabled = false;
51+
});
52+
// [END authstatelistener]
53+
54+
document.getElementById('quickstart-button').addEventListener('click', startSignIn, false);
55+
}
56+
57+
/**
58+
* Start the auth flow and authorizes to Firebase.
59+
* @param{boolean} interactive True if the OAuth flow should request with an interactive mode.
60+
*/
61+
function startAuth(interactive) {
62+
// Request an OAuth token from the Chrome Identity API.
63+
chrome.identity.getAuthToken({interactive: !!interactive}, function(token) {
64+
if (chrome.runtime.lastError && !interactive) {
65+
console.log('It was not possible to get a token programmatically.');
66+
} else if(chrome.runtime.lastError) {
67+
console.error(chrome.runtime.lastError);
68+
} else if (token) {
69+
// Authorize Firebase with the OAuth Access Token.
70+
var credential = firebase.auth.GoogleAuthProvider.credential(null, token);
71+
firebase.auth().signInWithCredential(credential).catch(function(error) {
72+
// The OAuth token might have been invalidated. Lets' remove it from cache.
73+
if (error.code === 'auth/invalid-credential') {
74+
chrome.identity.removeCachedAuthToken({token: token}, function() {
75+
startAuth(interactive);
76+
});
77+
}
78+
});
79+
} else {
80+
console.error('The OAuth Token was null');
81+
}
82+
});
83+
}
84+
85+
/**
86+
* Starts the sign-in process.
87+
*/
88+
function startSignIn() {
89+
document.getElementById('quickstart-button').disabled = true;
90+
if (firebase.auth().currentUser) {
91+
firebase.auth().signOut();
92+
} else {
93+
startAuth(true);
94+
}
95+
}
96+
97+
window.onload = function() {
98+
initApp();
99+
};

src/auth/index.html

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/auth/main.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
html, body {
2+
font-family: 'Roboto', 'Helvetica', sans-serif;
3+
}
4+
body {
5+
width: 400px;
6+
min-height: 400px;
7+
margin: 0;
8+
padding: 5px;
9+
}
10+
a {
11+
text-decoration: none;
12+
}
13+
li a {
14+
text-decoration: underline;
15+
color: #0288d1;
16+
}
17+
.mdl-grid {
18+
max-width: 1024px;
19+
margin: auto;
20+
}
21+
.mdl-layout__header-row {
22+
padding: 0;
23+
}
24+
.quickstart-user-details-container {
25+
margin-top: 20px;
26+
line-height: 25px;
27+
}
28+
#quickstart-sign-in-status {
29+
font-weight: bold;
30+
}
31+
pre {
32+
overflow-x: scroll;
33+
line-height: 18px;
34+
}
35+
code {
36+
white-space: pre-wrap;
37+
word-break: break-all;
38+
}
39+
h3 {
40+
background: url('firebase-logo.png') no-repeat;
41+
background-size: 40px;
42+
padding-left: 50px;
43+
line-height: 40px;
44+
}

src/auth/oauth.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/background.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
'use strict';
1+
var config = {
2+
apiKey: 'AIzaSyCbBsA6NBf-Ko1iIQZLcIR2cpspWslwx5I',
3+
authDomain: "fnplus-rle-mvp.firebaseapp.com",
4+
projectId: "fnplus-rle-mvp",
5+
appId: "1:1064007003546:web:187ca42dbcf8a58d"
6+
};
7+
firebase.initializeApp(config);
28

3-
console.log("Hello from background")
9+
/**
10+
* initApp handles setting up the Firebase context and registering
11+
* callbacks for the auth status.
12+
*
13+
* The core initialization is in firebase.App - this is the glue class
14+
* which stores configuration. We provide an app name here to allow
15+
* distinguishing multiple app instances.
16+
*
17+
* This method also registers a listener with firebase.auth().onAuthStateChanged.
18+
* This listener is called when the user is signed in or out, and that
19+
* is where we update the UI.
20+
*
21+
* When signed in, we also authenticate to the Firebase Realtime Database.
22+
*/
23+
function initApp() {
24+
// Listen for auth state changes.
25+
firebase.auth().onAuthStateChanged(function (user) {
26+
console.log('User state change detected from the Background script of the Chrome Extension:', user);
27+
});
28+
}
429

5-
chrome.browserAction.onClicked.addListener(function() {
6-
chrome.tabs.create({url: 'src/auth/index.html'});
7-
});
30+
window.onload = function () {
31+
initApp();
32+
};

0 commit comments

Comments
 (0)