Compare commits
8 Commits
e050595cd0
...
9a62e4077b
Author | SHA1 | Date | |
---|---|---|---|
9a62e4077b | |||
b81dee68d5 | |||
701861f685 | |||
1cc7382efa | |||
87631fa80a | |||
9efdd7ed48 | |||
5f4b22d2a9 | |||
9a6466e5ed |
@ -39,7 +39,7 @@ android {
|
||||
applicationId = 'hu.qwit.firka'
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||
minSdk = flutter.minSdkVersion
|
||||
minSdk = 23 // bump minSdk version to android 6, since isar db requires minSdk 23
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
versionCode = flutter.versionCode
|
||||
versionName = flutter.versionName
|
||||
@ -63,4 +63,4 @@ android {
|
||||
|
||||
flutter {
|
||||
source = '../..'
|
||||
}
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
class Constants {
|
||||
static const clientId = "kreta-ellenorzo-student-mobile-ios";
|
||||
}
|
||||
|
||||
class KretaEndpoints {
|
||||
static String kreta(String iss) => "https://$iss.e-kreta.hu";
|
||||
static const kretaIdp = "https://idp.e-kreta.hu";
|
||||
static const kretaLoginUrl = "https://idp.e-kreta.hu/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fprompt%3Dlogin%26nonce%3DwylCrqT4oN6PPgQn2yQB0euKei9nJeZ6_ffJ-VpSKZU%26response_type%3Dcode%26code_challenge_method%3DS256%26scope%3Dopenid%2520email%2520offline_access%2520kreta-ellenorzo-webapi.public%2520kreta-eugyintezes-webapi.public%2520kreta-fileservice-webapi.public%2520kreta-mobile-global-webapi.public%2520kreta-dkt-webapi.public%2520kreta-ier-webapi.public%26code_challenge%3DHByZRRnPGb-Ko_wTI7ibIba1HQ6lor0ws4bcgReuYSQ%26redirect_uri%3Dhttps%253A%252F%252Fmobil.e-kreta.hu%252Fellenorzo-student%252Fprod%252Foauthredirect%26client_id%3Dkreta-ellenorzo-student-mobile-ios%26state%3Drefilc_student_mobile%26suppressed_prompt%3Dlogin";
|
||||
|
||||
static const tokenGrantUrl = "https://idp.e-kreta.hu/connect/token";
|
||||
}
|
9
firka/lib/helpers/api/model/bank_account.dart
Normal file
9
firka/lib/helpers/api/model/bank_account.dart
Normal file
@ -0,0 +1,9 @@
|
||||
class BankAccount {
|
||||
|
||||
final List<String> addressDataList;
|
||||
|
||||
BankAccount({
|
||||
required this.addressDataList
|
||||
});
|
||||
|
||||
}
|
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']
|
||||
);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
final dio = Dio();
|
||||
|
||||
Future<String?> getAccessToken({
|
||||
required String code,
|
||||
|
||||
|
||||
}
|
40
firka/lib/helpers/api/token_grant.dart
Normal file
40
firka/lib/helpers/api/token_grant.dart
Normal file
@ -0,0 +1,40 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:firka/helpers/api/resp/token_grant.dart';
|
||||
import 'consts.dart';
|
||||
|
||||
final dio = Dio();
|
||||
|
||||
Future<TokenGrantResponse> getAccessToken(String code) async {
|
||||
// request to the KretaEndpoints.tokenGrantUrl endpoint
|
||||
|
||||
final headers = const <String, String>{
|
||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"accept": "*/*",
|
||||
"user-agent": "eKretaStudent/264745 CFNetwork/1494.0.7 Darwin/23.4.0",
|
||||
};
|
||||
|
||||
final formData = <String, String>{
|
||||
"code": code,
|
||||
"code_verifier": "DSpuqj_HhDX4wzQIbtn8lr8NLE5wEi1iVLMtMK0jY6c",
|
||||
"redirect_uri": "https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect",
|
||||
"client_id": Constants.clientId,
|
||||
"grant_type": "authorization_code",
|
||||
};
|
||||
|
||||
try {
|
||||
final response = await dio.post(KretaEndpoints.tokenGrantUrl, options: Options(headers: headers), data: formData);
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
return TokenGrantResponse.fromJson(response.data);
|
||||
case 401:
|
||||
throw Exception("Invalid grant");
|
||||
default:
|
||||
throw Exception("Failed to get access token, response code: ${response.statusCode}");
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
|
||||
}
|
0
firka/lib/helpers/db/db.dart
Normal file
0
firka/lib/helpers/db/db.dart
Normal file
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,
|
||||
);
|
||||
}
|
||||
}
|
@ -29,6 +29,9 @@ environment:
|
||||
# dependencies can be manually updated by changing the version numbers below to
|
||||
# the latest version available on pub.dev. To see which dependencies have newer
|
||||
# versions available, run `flutter pub outdated`.
|
||||
|
||||
isar_version: &isar_version ^4.0.0-dev.14
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
@ -36,11 +39,17 @@ dependencies:
|
||||
cupertino_icons: ^1.0.8
|
||||
flutter_launcher_icons: ^0.14.3
|
||||
flutter_native_splash: ^2.4.5
|
||||
dio: ^5.8.0+1
|
||||
isar: *isar_version
|
||||
isar_flutter_libs: *isar_version
|
||||
build_runner: any
|
||||
path_provider: ^2.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^5.0.0
|
||||
build_runner: any
|
||||
|
||||
flutter_native_splash:
|
||||
color: "#7CA021"
|
||||
|
Loading…
x
Reference in New Issue
Block a user