Suite API
continuous-integration/drone/push Build is passing Details

messagerie_lucas_test
Félix MIELCAREK 2 years ago
parent 0658b94412
commit 8e8298b4bb

@ -13,6 +13,7 @@ class Api {
get redirectUri => 'https://daflmusic.000webhostapp.com/callback/';
final _scopes = 'user-read-playback-state user-read-currently-playing';
String? _state;
String? _codeChallenge;
String? _encodedLogs;
final _tokenType = 'Bearer ';
@ -27,9 +28,11 @@ class Api {
Uri? _urlAuthorize;
get urlAuthorize => _urlAuthorize;
DateTime? _tokenEnd;
Random rng = Random();
Api() {
_state = _generateRandomString();
_state = _generateRandomString(16);
_codeChallenge = _generateRandomString(rng.nextInt(85) + 43);
_encodedLogs = base64.encode(utf8.encode("$_clientId:$_clientSecret"));
_urlAuthorize = Uri.https('accounts.spotify.com', 'authorize', {
'client_id': _clientId,
@ -37,15 +40,19 @@ class Api {
'redirect_uri': redirectUri,
'state': _state,
'scope': _scopes,
'show_dialog': 'true'
'show_dialog': 'false',
'code_challenge_method': 'S256',
'code_challenge': _codeChallenge
});
}
// for state value
String _generateRandomString() {
var r = Random();
return String.fromCharCodes(
List.generate(16, (index) => r.nextInt(33) + 89));
//random string generation
String _generateRandomString(int length) {
const chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890_.-~';
return String.fromCharCodes(Iterable.generate(
length, (_) => chars.codeUnitAt(rng.nextInt(chars.length))));
}
//session management
@ -108,7 +115,6 @@ class Api {
'Authorization': '$_tokenType $token',
'Content-Type': 'application/json'
});
print(response.statusCode);
var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
return decodedResponse['item']['id'];
}

@ -1,8 +1,9 @@
import 'dart:io';
import 'package:dafl_project_flutter/api/track.dart';
import 'package:dafl_project_flutter/main.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'track.dart';
class MyInAppBrowser extends InAppBrowser {
var options = InAppBrowserClassOptions(
crossPlatform:
@ -26,6 +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();
Track track = await MyApp.api.getTrackInfo(id);
print('${track.artist} ${track.name} ${track.albumImage}');*/
close();
}
}

@ -268,6 +268,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.4"
random_string:
dependency: "direct main"
description:
name: random_string
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
rive:
dependency: "direct main"
description:

@ -22,6 +22,7 @@ dependencies:
vibration: ^1.7.6
flutter_inappwebview: ^5.7.1
http: ^0.13.5
random_string: ^2.3.1
dev_dependencies:
flutter_test:

Loading…
Cancel
Save