-
Create a firebase project and configure a web app from Firebase Console.
-
Enable the Auth providers you would like to offer your users in the firebase console, under Auth > Sign-in methods.
-
Copy
public/sample-config.js
topublic/config.js
:
cp public/sample-config.js public/config.js
Then copy and paste the Web snippet code found in the firebase 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.
Google OAuth provider note
: You will need to ensure that the OAuth 2.0 Client ID you are using includes the Authorized redirect URI for your firebase handlerhttps://<firebase-project-id>.firebaseapp.com/__/auth/handler
. Navigate tohttps://console.cloud.google.com/apis/credentials?authuser=1&project=<firbase-project-id>
, click on the relevant client id in the "OAuth 2.0 Client IDs" list, addhttps://<firebase-project-id>.firebaseapp.com/__/auth/handler
to the "Authorized redirect URIs", and click Save.
-
Create a custom verifier from torus developer dashboard with following configuration:
-
Make sure to add a following JWT validation fields in custom verifier window (here is a related, helpful Firebase doc):-
aud
: firebase project id.iss
:https://securetoken.google.com/<firebase-project-id>
-
Use
sub
asJWT Verifier ID
field in custom verifier window. -
Use
https://www.googleapis.com/service_accounts/v1/jwk/[email protected]
as JWK Endpoint in custom verifier window
-
-
Replace
TORUS_DIRECT_SDK_VERIFIER_NAME
const in public/app.js file with your Verifier identifier
- In app.js file, when user is succesfully logged in, it fetches user's
idToken
anduid
inside firebase sdk'sonAuthStateChanged
callback and passes it togetTorusKey
function of customauth for constructing user's private key.
firebase.auth().onAuthStateChanged(async function(user) {
...
...
if (user) {
// fetch the id token of loggedIn user
const idToken = await firebase.auth().currentUser.getIdToken(/* forceRefresh */ true);
// Send token to torus nodes for constructing privateKey
const { privateKey, publicAddress } = await torusdirectsdk.getTorusKey(
TORUS_DIRECT_SDK_VERIFIER_NAME,
firebase.auth().currentUser.uid,
{ verifier_id: firebase.auth().currentUser.uid },
idToken,
);
handleSignedInUser(user, privateKey, publicAddress)
} else {
handleSignedOutUser();
}
});
Run:
npm install
Run:
npm run install