forked from firka/firka
add token grant response model and database service for token management
This commit is contained in:
28
firka/lib/helpers/api/resp/token_grant.dart
Normal file
28
firka/lib/helpers/api/resp/token_grant.dart
Normal 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']
|
||||
);
|
||||
}
|
||||
}
|
||||
15
firka/lib/helpers/db/models/token_model.dart
Normal file
15
firka/lib/helpers/db/models/token_model.dart
Normal 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
|
||||
}
|
||||
21
firka/lib/helpers/db/token_service.dart
Normal file
21
firka/lib/helpers/db/token_service.dart
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user