echidna_flutter library

Echidna Flutter

Client SDK for echidna_server. Use this library to verify licenses and features unlocked by them.

Installation

Add dependency to your project

To get started add the following dependency to your pubspec.yaml file:

dependencies:
  echidna_flutter:
    git:
      url: https://github.com/necodeIT/echidna_flutter.git

Initialize the SDK

Call the initializeEchidnaApi method in your main method before running the app.

import 'package:echidna_flutter/echidna_flutter.dart';

void main() {
    initializeEchidnaApi(baseUrl: 'https://echidna.your.domain', clientKey: 'your-client-key'; clientId: your-client-id);
    runApp(MyApp());
}

Implement UserIdRepository

For the SDK to work you need to implement a UserIdRepository that provides the current user id.

import 'package:echidna_flutter/echidna_flutter.dart';

class MyUserIdRepository extends UserIdRepository {}

You're most likely going to connect this to your preexisting user management system.

import 'package:echidna_flutter/echidna_flutter.dart';

class MyUserIdRepository extends UserIdRepository {
  final UserRepository _user;

  MyUserIdRepository(this._user) {
    watchAsync(_user);
  }

  @override
  FutureOr<void> build(Type trigger){
    data(_user.id);
  }
}

Initialize LicenseRepository

You also need to initialize the LicenseRepository with the UserIdRepository you just implemented (most likely in your auth module).

import 'package:echidna_flutter/echidna_flutter.dart';

class MyAuthModule extends Module {
  @override
  List<Module> get imports => [
    EchidnaModule(),
  ];

  @override
  void binds(Injector i) {
    // add your other bindings here
    i.initializeLicenseRepo(MyUserIdRepository.new); // this should be called last
  }
}

Use the SDK

Finally, you now can use the SDK to verify licenses and features unlocked by them.

import 'package:echidna_flutter/echidna_flutter.dart';

class MyFeature extends Module {}

class AppModule extends Module {
  @override
  void routes(RouteManager r){
    r.module('/my-feature', module: MyFeature(), guards: [FeatureGuard(myFeatureId)]);
  }
}

Classes

EchidnaApiService
Handles communication with the Echidna API.
EchidnaConfig
Configuration for the Echidna API.
EchidnaModule
Module for using the echidna client sdk.
FeatureGuard
Guards access to a route based on the user's license.
LicenseRepository
Holds the license status for the current user.
LicenseStatusDatasource
Datasource for getting the license status.
SignatureService
Signs requests sent to the server.
UserID
Wrapper class for a user ID.
UserIdRepository
Holds the user ID for the current user.

Extensions

LicenseRepoX on Injector
Injects the license repository.

Functions

initializeEchidnaApi({required String baseUrl, required String clientKey, required int clientId}) → void
Initializes the Echidna API with the given baseUrl and clientKey.