-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,468 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,56 @@ | ||
const { cert, initializeApp } = require('firebase-admin/app'); | ||
const { getAuth } = require('firebase-admin/auth'); | ||
const axios = require('axios').default; | ||
|
||
let firebaseAuth = null; | ||
|
||
function initializeAuth(serviceAccountKey) { | ||
const firebaseApp = initializeApp({ | ||
credential: cert(serviceAccountKey), | ||
}); | ||
|
||
firebaseAuth = getAuth(firebaseApp); | ||
} | ||
|
||
// Create a custom token with specific claims | ||
// Used to exchange for an ID token from firebase | ||
function getCustomToken() { | ||
if (!firebaseAuth) { | ||
throw new Error('Firebase auth not initizlied'); | ||
} | ||
|
||
return firebaseAuth.createCustomToken('simulator', { 'sim_backend': true }); | ||
} | ||
|
||
// Get an ID token from firebase using a previously created custom token | ||
function getIdTokenFromCustomToken(customToken) { | ||
if (!firebaseAuth) { | ||
throw new Error('Firebase auth not initizlied'); | ||
} | ||
|
||
// TODO: move into config somewhere | ||
const apiKey = 'AIzaSyBiVC6umtYRy-aQqDUBv8Nn1txWLssix04'; | ||
|
||
// Send request to auth emulator if using | ||
const urlPrefix = process.env.FIREBASE_AUTH_EMULATOR_HOST ? `http://${process.env.FIREBASE_AUTH_EMULATOR_HOST}/` : 'https://'; | ||
const url = `${urlPrefix}identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=${apiKey}`; | ||
|
||
return axios.post(url, { | ||
token: customToken, | ||
returnSecureToken: true, | ||
}) | ||
.then(response => { | ||
const responseBody = response.data; | ||
return responseBody.idToken; | ||
}) | ||
.catch(error => { | ||
console.error('FAILED TO GET ID TOKEN', error?.response?.data?.error); | ||
return null; | ||
}); | ||
} | ||
|
||
module.exports = { | ||
initializeAuth, | ||
getCustomToken, | ||
getIdTokenFromCustomToken, | ||
}; |
This file contains 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
This file contains 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
This file contains 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,20 @@ | ||
import * as React from 'react'; | ||
import * as ReactDom from 'react-dom'; | ||
import { DARK } from '../constants/theme'; | ||
|
||
import { Provider as StyletronProvider } from "styletron-react"; | ||
import { Client as Styletron } from "styletron-engine-atomic"; | ||
import ParentalConsentPage from '../../pages/ParentalConsentPage'; | ||
|
||
const reactRoot = document.getElementById('reactRoot'); | ||
|
||
const engine = new Styletron({ prefix: 'style' }); | ||
|
||
const userId = window.location.pathname.split('/').pop() | ||
|
||
ReactDom.render( | ||
<StyletronProvider value={engine} debugAfterHydration> | ||
<ParentalConsentPage theme={DARK} userId={userId} /> | ||
</StyletronProvider>, | ||
reactRoot | ||
); |
This file contains 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,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<link rel="apple-touch-icon" sizes="180x180" href="/static/icons/apple-touch-icon.png"> | ||
<link rel="icon" type="image/png" sizes="32x32" href="/static/icons/favicon-32x32.png"> | ||
<link rel="icon" type="image/png" sizes="16x16" href="/static/icons/favicon-16x16.png"> | ||
<title>Parental Consent for Simulator</title> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400&display=swap" rel="stylesheet"> | ||
<style> | ||
* { | ||
box-sizing: border-box; | ||
} | ||
body { | ||
overscroll-behavior: none; | ||
} | ||
html, body { | ||
position: relative; | ||
margin: 0; | ||
padding: 0; | ||
background-color: #dcdde1; | ||
font-family: 'Roboto', sans-serif; | ||
font-weight: 300; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="reactRoot"></div> | ||
</body> | ||
</html> |
This file contains 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
Oops, something went wrong.