-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from GoogleChromeLabs/dev
Enable Signal API, better config management, etc
- Loading branch information
Showing
16 changed files
with
5,479 additions
and
6,314 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import firebaseJson from './firebase.json' with { type: 'json' }; | ||
import { getFirestore } from 'firebase-admin/firestore'; | ||
import { initializeApp } from 'firebase-admin/app'; | ||
|
||
const is_localhost = process.env.NODE_ENV === 'localhost'; | ||
const env = is_localhost ? 'development' : 'production'; | ||
const _config = (await import(`./${env}.config.json`, {with:{type: 'json'}})).default; | ||
|
||
function generateApkKeyHash(fingerprint) { | ||
const hexString = fingerprint.replace(/:/g, ''); | ||
|
||
// Convert hex string to byte array | ||
const bytes = new Uint8Array(hexString.length / 2); | ||
for (let i = 0; i < hexString.length; i += 2) { | ||
bytes[i / 2] = parseInt(hexString.substr(i, 2), 16); | ||
} | ||
|
||
// Encode byte array to base64url | ||
const base64url = btoa(String.fromCharCode(...bytes)) | ||
.replace(/\+/g, '-') | ||
.replace(/\//g, '_') | ||
.replace(/=+$/, ''); | ||
|
||
return `android:apk-key-hash:${base64url}`; | ||
} | ||
|
||
const { hostname, port, associated_domains = [], secret, rp_name, project_name } = _config; | ||
|
||
const domain = port ? `${hostname}:${port}` : hostname; | ||
const origin = is_localhost ? `http://${domain}` : `https://${domain}`; | ||
|
||
const associated_origins = []; | ||
for (let domain of associated_domains) { | ||
const associated_origin = generateApkKeyHash(domain.sha256_cert_fingerprints); | ||
associated_origins.push(associated_origin); | ||
} | ||
|
||
const config = { | ||
env, | ||
hostname, | ||
domain, | ||
origin, | ||
secret: 'set your own secret in the config file', | ||
rp_name: rp_name || 'Passkeys Demo', | ||
project_name: project_name || 'passkeys-demo', | ||
associated_domains: [ | ||
origin, | ||
...associated_domains | ||
], | ||
associated_origins: [ | ||
origin, | ||
...associated_origins | ||
] | ||
}; | ||
|
||
function initializeFirestore() { | ||
if (is_localhost) { | ||
process.env.GOOGLE_CLOUD_PROJECT = config.project_name; | ||
process.env.FIRESTORE_EMULATOR_HOST = `${firebaseJson.emulators.firestore.host}:${firebaseJson.emulators.firestore.port}`; | ||
} | ||
|
||
initializeApp(); | ||
|
||
const store = getFirestore(process.env.FIRESTORE_DATABASENAME || ''); | ||
store.settings({ignoreUndefinedProperties: true}); | ||
return store; | ||
} | ||
|
||
const store = initializeFirestore(); | ||
|
||
export { config, store }; |
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,6 @@ | ||
{ | ||
"hostname": "localhost", | ||
"port": 8080, | ||
"rp_name": "Passkeys Demo", | ||
"project_name": "passkeys-demo" | ||
} |
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
Oops, something went wrong.