diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index 0fa6055..b8ed782 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -5,422 +5,438 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml
index 6ae284f..a82e8b9 100644
--- a/.idea/libraries/Dart_SDK.xml
+++ b/.idea/libraries/Dart_SDK.xml
@@ -1,25 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Sources/dafl_project_flutter/lib/api/api.dart b/Sources/dafl_project_flutter/lib/api/api.dart
index 8adf5c6..982282c 100644
--- a/Sources/dafl_project_flutter/lib/api/api.dart
+++ b/Sources/dafl_project_flutter/lib/api/api.dart
@@ -8,7 +8,7 @@ import 'track.dart';
class Api {
//from dashboard
final _clientId = '7ceb49d874b9404492246027e4d68cf8';
- final _clientSecret = '98f9cb960bf54ebbb9ad306e7ff919cb'; // TODO : hide it
+ final _clientSecret = '98f9cb960bf54ebbb9ad306e7ff919cb';
//for web api
get redirectUri => 'https://daflmusic.000webhostapp.com/callback/';
@@ -27,18 +27,16 @@ class Api {
//other
final _client = http.Client();
- Uri? _urlAuthorize;
+ late Uri _urlAuthorize;
get urlAuthorize => _urlAuthorize;
DateTime? _tokenEnd;
- Random rng = Random();
Api() {
_state = _generateRandomString(16);
- _codeVerifier =
- base64UrlEncode(_generateRandomString(rng.nextInt(85) + 43).codeUnits);
- _codeChallenge =
- base64UrlEncode(sha256.convert(utf8.encode(_codeVerifier)).bytes);
+ _codeVerifier = _generateRandomString(_generateRandomInt(43, 128));
+ _codeChallenge = _generateCodeChallenge();
+ print(_codeChallenge);
_encodedLogs = base64.encode(utf8.encode("$_clientId:$_clientSecret"));
_urlAuthorize = Uri.https('accounts.spotify.com', 'authorize', {
'client_id': _clientId,
@@ -52,17 +50,25 @@ class Api {
});
}
- //random string generation
+ //PKCE generations
- String _generateRandomString(int length) {
+ _generateRandomInt(int min, int max) {
+ return min + Random().nextInt(max - min);
+ }
+
+ _generateRandomString(int length) {
const chars =
- 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890_.-~';
+ 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
return String.fromCharCodes(Iterable.generate(
- length, (_) => chars.codeUnitAt(rng.nextInt(chars.length))));
- /*var test = String.fromCharCodes(Iterable.generate(
- length, (_) => chars.codeUnitAt(rng.nextInt(chars.length))));
- print(test);
- return test;*/
+ length, (_) => chars.codeUnitAt(Random().nextInt(chars.length))));
+ }
+
+ _generateCodeChallenge() {
+ //care : base64Url doesn't work
+ return base64Encode(sha256.convert(utf8.encode(_codeVerifier)).bytes)
+ .replaceAll('+', '-')
+ .replaceAll('/', '_')
+ .replaceAll('=', '');
}
//session management
@@ -88,7 +94,6 @@ class Api {
'Content-Type': 'application/x-www-form-urlencoded'
});
var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
- print(decodedResponse);
_accessToken = decodedResponse['access_token'];
_expiresIn = decodedResponse['expires_in'];
_tokenEnd = DateTime.now().add(Duration(seconds: _expiresIn!));
diff --git a/Sources/dafl_project_flutter/lib/api/in_app_browser.dart b/Sources/dafl_project_flutter/lib/api/in_app_browser.dart
index 4d8751b..0424e86 100644
--- a/Sources/dafl_project_flutter/lib/api/in_app_browser.dart
+++ b/Sources/dafl_project_flutter/lib/api/in_app_browser.dart
@@ -27,9 +27,9 @@ class MyInAppBrowser extends InAppBrowser {
Future onLoadStart(url) async {
if (url!.origin + url.path == MyApp.api.redirectUri) {
await MyApp.api.requestUserAuthorization(url);
- String id = await MyApp.api.getCurrentlyPlayingTrack();
+ /*String id = await MyApp.api.getCurrentlyPlayingTrack();
Track track = await MyApp.api.getTrackInfo(id);
- print('${track.artist} ${track.name} ${track.albumImage}');
+ print('${track.artist} ${track.name} ${track.albumImage}');*/
close();
}
}