Initializing Fingerprint

After importing the fingerprint_dart_auth_sdk into your Flutter project, as mentioned in the previous step, it's time to initialize Fingerprint using the SDK.

There are two methods you can use to achieve this:

  • Using environment variables

  • Using service account methods

Using Environment Variables

To use environment variables to initialize Fingerprint, first obtain your project ID and API key.

Your project ID can be found in the environments tab of your "Project settings" page via the link:

https://dashboard.fingerprint.com/workspaces/<your-first-project/environments

Your project API key can be found via the API keys tab of your project :

https://dashboard.fingerprint.com/workspaces/<your-project-name>/api-keys

Set the environment variables for your project ID and API key as follows:

set FINGERPRINT_API_KEY=your_api_key
set FINGERPRINT_PROJECT_ID=your_project_id

Initialize Firebase with environment variables.

   import 'package:fingerprint_dart_auth_sdk/fingerprint_dart_auth_sdk.dart';
   
   
   void main() async {
     //Pass the enviroment variables into the function below, I.E API key and project ID
     FingerprintApp.initializeAppWithEnvironmentVariables(
       apiKey: FINGERPRINT_API_KEY,
       projectId: FINGERPRINT_PROJECT_ID,
     );
      
     // Get Firebase auth instance for this project
     FingerprintApp.instance.getAuth();

     // Example: Sign in with email and password
     try {
       final user = await FingerprintApp.fingerprintAuth
        ?.createUserWithEmailAndPassword('[email protected]', 'password');
        
       final await userCredential = await FingerprintApp.fingerprintAuth
       ?.signInWithEmailAndPassword('[email protected]', 'password'); 
       
       print('Signed in as ${userCredential?.user.email}');
     } catch (e) {
       print('Sign-in error: $e');
     }
   }

Use the FingerprintApp.initializeAppWithEnvironmentVariables() method to initialize Fingerprint passing in the environment variables.

Try signing in a user with the FingerprintApp.fingerprintAuth?.signInWithEmailAndPassword() authentication method, passing in required arguments. If login is successful, a return user's credential userCredential is returned.

circle-info

Using the environment variables to initialize Fingerprint currently works on backend and frontend (all platforms).

Initializing Fingerprint using the Fingerprint Dart Auth SDK with the FingerprintApp.initializeAppWithEnvironmentVariables() method allows for user creation and management on both the client and server side.

Optional: Use Fingerprint Web SDK for frontend, OR use this SDK on backend for user operations.

Environment Variables can be used for:

  • ✅ Backend user creation

  • ✅ Password resets

  • ✅ Authentication

  • ❌ Token verification

Using Service Account Methods

To obtain the service account keys follow the steps below:

  • Login into your Fingerprint dashboard.

  • Click on the Fingerprint project you want to get the service keys.

  • Click on the gear icon in "Project Overview" on the left sidebar

  • Click on "Project settings".

  • Select the "Service account" tab on the "Project settings" page.

  • Click the "Generate new private key" button to download your serviceAccountKey.json file.

  • Save the serviceAccountKey.json file with your project directory.

circle-exclamation

Last updated