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

@ -1,8 +1,9 @@
import 'dart:io'; import 'dart:io';
import 'package:dafl_project_flutter/api/track.dart';
import 'package:dafl_project_flutter/main.dart'; import 'package:dafl_project_flutter/main.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'track.dart';
class MyInAppBrowser extends InAppBrowser { class MyInAppBrowser extends InAppBrowser {
var options = InAppBrowserClassOptions( var options = InAppBrowserClassOptions(
crossPlatform: crossPlatform:
@ -26,6 +27,9 @@ class MyInAppBrowser extends InAppBrowser {
Future onLoadStart(url) async { Future onLoadStart(url) async {
if (url!.origin + url.path == MyApp.api.redirectUri) { if (url!.origin + url.path == MyApp.api.redirectUri) {
await MyApp.api.requestUserAuthorization(url); 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(); close();
} }
} }

@ -268,6 +268,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.4" 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: rive:
dependency: "direct main" dependency: "direct main"
description: description:

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

Loading…
Cancel
Save