From 1427f92b9a13ce894251dc1624c5532840c23861 Mon Sep 17 00:00:00 2001 From: Lukas Nagel Date: Sat, 2 Nov 2024 14:40:17 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20tv=20refresh=20tokens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/auth/device_code.dart | 8 +++++++- lib/auth/login_manager.dart | 7 ++++++- lib/views/detail_views/show_detail.dart | 17 +++++++++-------- lib/widgets/custom_image.dart | 4 +++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/auth/device_code.dart b/lib/auth/device_code.dart index 268ab8d..332c1bc 100644 --- a/lib/auth/device_code.dart +++ b/lib/auth/device_code.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; +import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/auth/auth_info.dart'; import 'package:qr_flutter/qr_flutter.dart'; @@ -78,6 +79,7 @@ class DeviceCode { interval, authInfo.clientId, authInfo.tokenUrl, + scope, ); return token; @@ -89,7 +91,7 @@ class DeviceCode { } Future pollForToken( - String deviceCode, int interval, String clientId, String tokenUrl) async { + String deviceCode, int interval, String clientId, String tokenUrl, String scope) async { while (true) { await Future.delayed(Duration(seconds: interval)); @@ -102,6 +104,7 @@ class DeviceCode { 'client_id': clientId, 'grant_type': 'urn:ietf:params:oauth:grant-type:device_code', 'device_code': deviceCode, + 'scope': scope }, ); @@ -109,6 +112,9 @@ class DeviceCode { final tokenResponse = json.decode(response.body); print('Access token: ${tokenResponse['access_token']}'); + Preferences.prefs?.setString("RefreshToken", tokenResponse['refresh_token']); + print('Refresh token: ${tokenResponse['refresh_token']}'); + return tokenResponse['access_token']; } else { final errorResponse = json.decode(response.body); diff --git a/lib/auth/login_manager.dart b/lib/auth/login_manager.dart index 695e9c4..81a4311 100644 --- a/lib/auth/login_manager.dart +++ b/lib/auth/login_manager.dart @@ -19,7 +19,12 @@ class LoginManager { LoginManager(AuthInfo authInfo) { if (PlatformGlobals.isTv) { - // Do nothing + client = OAuth2Client( + authorizeUrl: authInfo.authorizeUrl, + tokenUrl: authInfo.tokenUrl, + redirectUri: "my.test.app:/oauth2redirect", // TODO + customUriScheme: "my.test.app", + ); } else if (!PlatformGlobals.isWeb) { client = OAuth2Client( authorizeUrl: authInfo.authorizeUrl, diff --git a/lib/views/detail_views/show_detail.dart b/lib/views/detail_views/show_detail.dart index a712b6c..8721a57 100644 --- a/lib/views/detail_views/show_detail.dart +++ b/lib/views/detail_views/show_detail.dart @@ -40,6 +40,12 @@ class ShowDetailView extends StatelessWidget { List seasons = []; for (var element in items) { + String imageUrl = Globals.PictureNotFoundUrl; + + if (element.posterUrl != null) { + imageUrl = "${element.posterUrl!}?height=300"; + } + seasons.add( Padding( padding: const EdgeInsets.all(8.0), @@ -54,7 +60,7 @@ class ShowDetailView extends StatelessWidget { width: 300 * (9 / 14), fit: BoxFit.cover, image: CachedNetworkImageProvider( - element.posterUrl ?? Globals.PictureNotFoundUrl, + imageUrl, headers: BaseApi.getHeaders(), ), ), @@ -85,12 +91,6 @@ class ShowDetailView extends StatelessWidget { ); } - String imageUrl = Globals.PictureNotFoundUrl; - - if (itemModel.backdropUrl != null) { - imageUrl = "${itemModel.backdropUrl!}?height=300"; - } - return SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -109,7 +109,8 @@ class ShowDetailView extends StatelessWidget { }, blendMode: BlendMode.dstIn, child: CustomImage( - imageUrl: imageUrl, + imageUrl: + itemModel.backdropUrl ?? Globals.PictureNotFoundUrl, height: 300, width: double.infinity, fit: BoxFit.cover, diff --git a/lib/widgets/custom_image.dart b/lib/widgets/custom_image.dart index e17e203..9c73afc 100644 --- a/lib/widgets/custom_image.dart +++ b/lib/widgets/custom_image.dart @@ -8,13 +8,15 @@ class CustomImage extends StatelessWidget { required this.imageUrl, this.fit, this.width, - this.height, + this.height, + this.disableAdaptiveImage = false, }); final String imageUrl; final BoxFit? fit; final double? width; final double? height; + final bool disableAdaptiveImage; @override Widget build(BuildContext context) {