From e978459c191cd1ae09d5237c7e47f023a51cf719 Mon Sep 17 00:00:00 2001 From: balint1414 Date: Mon, 8 Sep 2025 21:00:58 +0200 Subject: [PATCH] =?UTF-8?q?kr=C3=A9ta=20login=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firka/lib/helpers/api/consts.dart | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/firka/lib/helpers/api/consts.dart b/firka/lib/helpers/api/consts.dart index 2dee56d..f0c4021 100644 --- a/firka/lib/helpers/api/consts.dart +++ b/firka/lib/helpers/api/consts.dart @@ -1,11 +1,18 @@ import 'dart:convert'; import 'dart:math'; - +import 'dart:io'; import 'package:crypto/crypto.dart'; import 'package:firka/main.dart'; +import 'dart:typed_data'; class Constants { - static const clientId = "kreta-ellenorzo-student-mobile-android"; + static String get clientId { + if (Platform.isAndroid) { + return "kreta-ellenorzo-student-mobile-android"; + } else { + return "kreta-ellenorzo-student-mobile-ios"; + } + } static const applicationId = "hu.ekreta.student"; static const applicationVersion = "5.7.0"; static String userAgent = "$applicationId/$applicationVersion" @@ -42,6 +49,15 @@ class KretaEndpoints { return base64Url.encode(digest.bytes).replaceAll('=', ''); } + static String generateStateOrNonce([int length = 16]) { + final random = Random.secure(); + final bytes = Uint8List(length); + for (int i = 0; i < length; i++) { + bytes[i] = random.nextInt(256); + } + return base64Url.encode(bytes).replaceAll('=', ''); + + } static String kreta(String iss) { if (iss == "firka-test") { return kretaBase; @@ -52,13 +68,15 @@ class KretaEndpoints { static final String codeVerifier = _generateCodeVerifier(); static final String _codeChallenge = _generateCodeChallenge(codeVerifier); - + static final String stateOrNonce = generateStateOrNonce(); + static final String clientId = Constants.clientId; + static String kretaIdp = "https://idp.e-kreta.hu"; static String kretaLoginUrl = - "$kretaIdp/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fredirect_uri%3Dhttps%253A%252F%252Fmobil.e-kreta.hu%252Fellenorzo-student%252Fprod%252Foauthredirect%26client_id%3Dkreta-ellenorzo-student-mobile-android%26response_type%3Dcode%26prompt%3Dlogin%26state%3DaOPUjQU3sXBVRjQQkmYT8g%26nonce%3D3qtS0kDcaHIUGkkEcL1-5g%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%3D$_codeChallenge%26code_challenge_method%3DS256%26suppressed_prompt%3Dlogin"; + "$kretaIdp/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fredirect_uri%3Dhttps%253A%252F%252Fmobil.e-kreta.hu%252Fellenorzo-student%252Fprod%252Foauthredirect%26client_id%3D$clientId%26response_type%3Dcode%26prompt%3Dlogin%26state%3D$stateOrNonce%26nonce%3D$stateOrNonce%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%3D$_codeChallenge%26code_challenge_method%3DS256%26suppressed_prompt%3Dlogin"; static String kretaLoginUrlRefresh(String username, String schoolId) => - "$kretaIdp/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fredirect_uri%3Dhttps%253A%252F%252Fmobil.e-kreta.hu%252Fellenorzo-student%252Fprod%252Foauthredirect%26client_id%3Dkreta-ellenorzo-student-mobile-android%26response_type%3Dcode%26login_hint%3D$username%26prompt%3Dlogin%26state%3DaOPUjQU3sXBVRjQQkmYT8g%26nonce%3D3qtS0kDcaHIUGkkEcL1-5g%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%3D$_codeChallenge%26code_challenge_method%3DS256%26institute_code%3D$schoolId%26suppressed_prompt%3Dlogin"; + "$kretaIdp/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fredirect_uri%3Dhttps%253A%252F%252Fmobil.e-kreta.hu%252Fellenorzo-student%252Fprod%252Foauthredirect%26client_id%3D$clientId%26response_type%3Dcode%26login_hint%3D$username%26prompt%3Dlogin%26state%3D$stateOrNonce%26nonce%3D$stateOrNonce%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%3D$_codeChallenge%26code_challenge_method%3DS256%26institute_code%3D$schoolId%26suppressed_prompt%3Dlogin"; static String tokenGrantUrl = "$kretaIdp/connect/token"; static String getStudentUrl(String iss) =>