rook_auth 0.1.0
rook_auth: ^0.1.0 copied to clipboard
Grant usage permissions to other rook packages.
Rook authorization #
This is the main package required by all rook packages to enable their usage.
Features #
- Obtain and save authorization to use other rook packages with your client UUID.
Getting started #
Logging #
If you want to see the logs generated by this package
Install the logger package:
logging: ">=1.0.0 <2.0.0"
Add the following snippet in your main() function:
void main() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
if (kDebugMode) {
print('${record.level.name}: ${record.time}: ${record.message}');
}
});
runApp(RookApp());
}
Usage #
You must check authorization every time your app starts or before using other rook packages.
- Create an
AuthorizationProviderinstance providing the core URL without https.
import 'package:rook_auth/rook_auth.dart';
final provider = AuthorizationProvider('api2.rookmotion.review');
- call
getAuthorizationproviding your client UUID, this will ask the server for a token which contains the packages you are allowed to use, and save this information in the device's local preferences.
void initialize() async {
final result = await provider.getAuthorization(clientUUID);
}
This method returns a Future of AuthorizationResult described below:
class AuthorizationResult {
final AuthorizationOrigin origin; // Where the authorization was retrieved from.
final Authorization authorization; // Authorization returned by server/preferences.
}
enum AuthorizationOrigin {
remote, // The authorization was retrieved from server.
local // The authorization was retrieved from preferences, this happens when the device does not have an active internet connection or if the request to the server fails.
}
class Authorization {
DateTime authorizedUntil; // Expire date (UTC).
Map<Feature, bool> features; // Features (packages) that are enabled or disabled.
}
Additional information #
The first time your users use this package they MUST have an active internet connection otherwise the request will fail and a default authorization will be returned.
- The default authorization has all packages disabled.
Authorization is stored in device's shared preferences, if your app is also using shared preferences
keep in mind that calling clear on the SharedPreferences instance will also delete this package
registries.