1
0
forked from firka/firka

add token grant response model and database service for token management

This commit is contained in:
zypherift
2025-03-12 00:00:52 +01:00
parent 1cc7382efa
commit 701861f685
3 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
class TokenGrantResponse {
final String idToken;
final String accessToken;
final int expiresIn;
final String tokenType;
final String refreshToken;
final String scope;
TokenGrantResponse({
required this.idToken,
required this.accessToken,
required this.expiresIn,
required this.tokenType,
required this.refreshToken,
required this.scope
});
factory TokenGrantResponse.fromJson(Map<String, dynamic> json) {
return TokenGrantResponse(
idToken: json['id_token'],
accessToken: json['access_token'],
expiresIn: json['expires_in'],
tokenType: json['token_type'],
refreshToken: json['refresh_token'],
scope: json['scope']
);
}
}

View File

@@ -0,0 +1,15 @@
import 'package:flutter/foundation.dart';
import 'package:isar/isar.dart';
part 'token_model.g.dart';
class TokenModel {
Id id = Isar.autoIncrement; // Auto-increment internal ID
@Index(unique: true, replace: true)
int? StudentId; // Custom unique student identifier
String? tokenId; // Unique identifier for the token if needed
String? accessToken; // The main auth token
String? refreshToken; // Token used to refresh the access token
DateTime? expiryDate; // When the token expires
}

View File

@@ -0,0 +1,21 @@
import 'package:isar/isar.dart';
import 'package:path_provider/path_provider.dart';
import 'models/token_model.dart';
class TokenService {
late Future<Isar> db;
// Initialize the database
TokenService() {
db = openDB();
}
// Open the Isar database
Future<Isar> openDB() async {
final dir = await getApplicationDocumentsDirectory();
return await Isar.open(
[TokenModelSchema],
directory: dir.path,
);
}
}